标签:prime std ++ unsigned cstring 枚举 str bre phi
https://www.lydsy.com/JudgeOnline/problem.php?id=2705
先化简。。
化简出来,这个函数就是$id*id*\mu=id*\varphi$
可以暴力枚举n的因子求。。
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #include<vector> 5 using namespace std; 6 #define fi first 7 #define se second 8 #define mp make_pair 9 #define pb push_back 10 typedef long long ll; 11 typedef unsigned long long ull; 12 typedef pair<int,int> pii; 13 bool nprime[100100]; 14 ll prime[30100],len; 15 ll phi(ll x) 16 { 17 ll i,ans=x; 18 for(i=1;prime[i]*prime[i]<=x;i++) 19 if(x%prime[i]==0) 20 { 21 ans=ans/prime[i]*(prime[i]-1); 22 while(x%prime[i]==0) x/=prime[i]; 23 } 24 if(x>1) ans=ans/x*(x-1); 25 return ans; 26 } 27 int main() 28 { 29 ll i,j; 30 nprime[1]=1; 31 for(i=2;i<=100000;i++) 32 { 33 if(!nprime[i]) prime[++len]=i; 34 for(j=1;j<=len&&i*prime[j]<=100000;j++) 35 { 36 nprime[i*prime[j]]=1; 37 if(i%prime[j]==0) break; 38 } 39 } 40 ll n,ans=0; 41 scanf("%lld",&n); 42 for(i=1;i*i<=n;i++) 43 if(n%i==0) 44 { 45 ans+=i*phi(n/i); 46 if(n/i!=i) 47 ans+=(n/i)*phi(i); 48 } 49 printf("%lld",ans); 50 return 0; 51 }
标签:prime std ++ unsigned cstring 枚举 str bre phi
原文地址:https://www.cnblogs.com/hehe54321/p/9372735.html