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