标签:
直接欧拉函数
int Euler(int n) { int ret = n; for(int i = 2; i*i <= n; ++i) { if(n % i == 0) { n /= i; ret = ret - ret/i; } while(n % i == 0) n /= i; } if(n > 1) ret = ret - ret/n; return ret; }递推快速求欧拉函数
int prime[100010],phi[1000010]; bool unprime[1000010]; __int64 sum[1000010]; void Euler() { int i,j,k = 0; for(i = 2; i <= 1000000; i++) { if(!unprime[i]) { prime[k++] = i; phi[i] = i-1; } for(j = 0; j < k && prime[j]*i <= 1000000; j++) { unprime[prime[j] *i] = true; if(i % prime[j] != 0) { phi[prime[j]*i] = phi[i]*(prime[j]-1); } else { phi[prime[j]*i] = phi[i]*prime[j]; break; } } } }
标签:
原文地址:http://blog.csdn.net/lianai911/article/details/45060915