数学/欧拉函数/sgu 102 Coprimes/poj 2407 Relatives

 

题意

  给出一个数n,求出比n小且与n互质的个数

分析

  欧拉函数模板

  通式:

  

  欧拉函数还有几个性质:

  1.若p为质数,则φ(p)=p-1

  2.若p为质数,则φ(p^a)=(p-1)*p^(a-1)

  3.若p,q互质,则φ(p*q)=φ(p)*φ(q)
 
Accepted Code
 
 1 /*
 2     PROBLEM:sgu102 poj 2407
 3     AUTHER:Rinyo
 4     MEMO:Euler's totient function 欧拉函数
 5 */
 6 
 7 
 8 #include<cstdio>
 9 int n;
10 int main()
11 {
12     scanf("%d",&n);
13     while (n!=0)
14     {
15         int p=2,ans=n;
16         while(n!=1)
17         {
18               if(n%p==0) 
19               {
20                 ans=ans*(p-1)/p;
21                 while(n%p==0) n/=p;
22              }
23               p++;
24         }
25         printf("%d",ans);
26         scanf("%d",&n);
27     }
28     return 0;
29 }

 

posted @ 2012-12-02 17:00  Rinyo  阅读(281)  评论(0编辑  收藏  举报