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;
}