1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int maxn=1e7+5;
 4 int n,phi[maxn];
 5 void phi_table(){
 6     phi[0]=0,phi[1]=1;//1的欧拉函数值为1,唯一与1互质的数
 7     for(int i=2;i<maxn;++i)phi[i]=i;//先初始化为其本身
 8     for(int i=2;i<maxn;++i){
 9         if(phi[i]==i){//如果欧拉函数值仍为其本身,说明i为素数
10             for(int j=i;j<maxn;j+=i)//把i的欧拉函数值改变,同时也把能被素因子i整除的数的欧拉函数值改变
11                 phi[j]=phi[j]/i*(i-1);
12         }
13     }
14 }
15 int main(){
16     phi_table();
17     while(cin>>n&&n)
18         cout<<phi[n]<<endl;
19     return 0;    
20 }

 

相关文章:

  • 2022-12-23
  • 2022-02-22
  • 2022-01-10
  • 2021-07-13
  • 2022-01-09
  • 2022-01-07
猜你喜欢
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2022-12-23
  • 2021-04-23
  • 2022-01-19
相关资源
相似解决方案