Light Oj 1098 A New Function 因子和

来源:互联网 发布:alias软件快捷键作用 编辑:程序博客网 时间:2024/06/06 03:35

http://www.lightoj.com/volume_showproblem.php?problem=1098

枚举  1  到 sqrt(n),我们知道 所有 有相同因子 a,他们相对于 a 的另外一个因子 应该成为一个等差数列。

例如:  2 ,4, 6, 8.。。。对于 因子 2  ,对应的因子分别为1,2,3,4,。

枚举每一个因子,把该因子出现的次数统计出来,对应因子出现 的序列求出来即可。

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;typedef __int64 LL;int main(){    LL T,tt=0;    cin>>T;    LL n;    while(T--)    {        cin>>n;        LL i,j,k,m,ans=0,p,q,d;        m=(LL)sqrt(n+0.5);        for(i=2;i<=m;i++)        {            ans+=i;            p=i+1;            q=n/i;            if(q<p)continue;            ans+=(q-p+1)*i;//因子 i  出现的所有和            ans+=(p+q)*(q-p+1)/2;// 因子  i 对应因子出现的所有和        }        cout<<"Case "<<++tt<<": "<<ans<<endl;    }    return 0;}


0 0
原创粉丝点击