求欧拉函数

来源:互联网 发布:淘宝网电脑版登录页面 编辑:程序博客网 时间:2024/06/13 07:17
 int euler(int x)//求欧拉函数  
  • {  
  •     int i, res = x;  
  •     for(i=2; i<(int)sqrt(x*1.0)+1; i++)  
  •     {  
  •         if(x%i==0)  
  •         {  
  •             res = res / i * (i-1);  
  •             while(x%i==0)  
  •                 x /= i;  
  •         }  
  •     }  
  •     if(x > 1)  
  •         res = res / x * (x-1);  
  •     return res;  
  • }  
  • 原创粉丝点击