-
#include<iostream> #include<cmath> //#define LL long long typedef long long LL; using namespace std; int phi[1000005]; int enlerFun(int n) { int count = n; for(int i=2;i<=n;i++) if(n % i == 0) { count -= count / i; while(n % i == 0) n /= i; } return count; } void enlerPhi(){ memset(phi,0,sizeof(phi)); for (int i = 2 ; i <= 1000003 ; i ++ ){ if( !phi[i] ){ for(int j = i ; j <= 1000003 ; j += i){ if (!phi[j]){phi [j ] = j ;} //标记合数 等于一个数 phi [j] = phi [j] / i * ( i - 1 ) ; } } } } void pt(){ for(int i=1;i<=100;i++){ printf("%d(%d) ",i,phi[i]); } } LL work(LL x){ LL sum=0; for(LL i=2;i<=x;i++){ sum=sum+phi[i]; } return sum; } int main(){ enlerPhi(); //pt(); LL x; while(scanf("%I64d",&x) && x!=0){ printf("%I64d\n",work(x)); } return 0; }
poj2478
最新推荐文章于 2020-07-21 15:08:37 发布