gcd(i,n)=p
gcd(i/p,n/p)=p
若p是n的约数,那么gcd(i,n)==p的有φ(n/p)
∑ i*euler(n/i)+(n/i)*euler(i) (n%i==0)
#include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<vector> #include<queue> #include<map> #include<set> #include<algorithm> using namespace std; inline void read(long long &a) { long long k=1; a=0; char c=getchar(); while(c<‘0‘||‘9‘<c){if(c==‘-‘)k=-1; c=getchar();} while(‘0‘<=c&&c<=‘9‘){a=a*10+c-‘0‘; c=getchar();} a*=k; } inline void write(long long a) { if (a<0){putchar(‘-‘);a=-a;} if (a>9)write(a/10); putchar(a%10+‘0‘); return ; } long long euler(long long x) { long long now=x,i; for(i=2;i<=sqrt(x);i++) { if(x%i==0) { now=now/i*(i-1); while(x%i==0) x/=i; } } if(x>1) now=now/x*(x-1); return now; } int main() { long long n,i; while (~scanf("%lld",&n)) { long long ans=0; for (i=1;i<sqrt(n);i++) { if (n%i==0) ans+=i*euler(n/i)+(n/i)*euler(i); } if (i*i==n) ans+=i*euler(i); cout<<ans<<endl; } return 0; }
POJ 2480 Longge's problem
原文地址:https://www.cnblogs.com/applechina/p/10556174.html
时间: 2024-10-12 12:24:38