poj2478

来源:互联网 发布:宋太宗997 知乎 编辑:程序博客网 时间:2024/04/29 19:40
  • #include<iostream>#include<cmath>//#define LL long longtypedef 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;}
0 0
原创粉丝点击