Description
"Oh, I know, I know!" Longge shouts! But do you know? Please solve it.
Input
A number N per line.
Output
Sample Input
2 6
Sample Output
3 15
设函数g(n) = gcd(i,n) (1<=i<=n),由积性函数的定义,g(n)=g(m1)*g(m2) (n=m1*m2 且 (m1, m2)= 1),所以g是积性函数。由具体数学上的结论,积性函数的和也是积性的。所以f(n) = ∑gcd(i, n)也是积性函数。由初等数论中的定理,如果f(n)是不恒为0的数论函数,n>1时 n=p1^a1*p2^a2*...*ps^as,那么f(n)是积性函数的充要条件是f(1)=1,及f(n) = f(p1^a1)*f(p2^a2)*...f(pr^ar)。所以只要求f(pi^ai)就好,如果d是n的一个约数,那么1<=i<=n中gcd(i,n) = d的个数是phi(n/d),即n/d的欧拉函数
f(pi^ai) = Φ(pi^ai)+pi*Φ(pi^(ai-1))+pi^2*Φ(pi^(ai-2))+...+pi^(ai-1)* Φ(pi)+ pi^ai *Φ(1)
= pi^(ai-1)*(pi-1) + pi*pi^(ai-2)*(pi-1)....+pi^ai
= pi^ai*(1+ai*(1-1/pi))
f(n) = p1^a1*p2^a2...*pr^ar*(1+a1*(1-1/p1))*(1+a2*(1-1/p2))*...
= n*(1+a1*(1-1/p1))*(1+a2*(1-1/p2))*...
#include<stdio.h>
#include<string>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <cstdio>
#include <cmath>
#include <string>
#include <stack>
#include <cctype>
using namespace std;
int main()
{
__int64 n;
while(~scanf("%I64d",&n))
{
__int64 i,j,k,l,ans,v;
ans=n;
v=sqrt(n);
for(i=2; i<=v; i++)
{
if(n%i==0)
{
k=0;
l=i;
while(n%l==0)
{
k++;
n/=l;
}
ans+=ans*k*(l-1)/l;
}
}
if (n!=1)
{
ans = ans + ans*(n-1)/n;
}
printf("%I64d\n", ans);
}
return 0;
}