证明详细的博客:http://blog.csdn.net/hillgong/article/details/4214327
模板:
1 #include<iostream> 2 #include<algorithm> 3 #include<queue> 4 #include<cstdio> 5 #include<cstring> 6 #define CLR(a,b) memset(a,b,sizeof b) 7 #define inf 0x3f3f3f3f 8 #define maxx(a,b) a>b?a:b 9 using namespace std; 10 typedef long long ll; 11 12 int Euler(int n){ 13 if(n==1) 14 return 1; 15 int res = n; 16 for(int i = 2; i*i <= n;i++){ 17 if(n%i==0){ 18 res = res/i*(i-1); 19 while (n%i==0) { 20 n/=i; 21 } 22 } 23 } 24 if(n>1) res = res/n*(n-1); 25 return res; 26 } 27 int main(){ 28 int t; 29 scanf("%d",&t); 30 while(t--){ 31 int n; 32 scanf("%d",&n); 33 int res = Euler(n); 34 printf("%d\n",res); 35 } 36 return 0; 37 }
模板博客:http://blog.csdn.net/henuwhr/article/details/77448332
时间: 2024-10-09 08:52:21