poj 2407 Relatives

上一题是欧拉函数打表,这一题赤裸裸的欧拉函数;

就当熟悉下模板把;其实自己以前也没敲过```

 1 #include<cstdio>
 2 using namespace std;
 3 long long MakePhi(long long n)
 4 {
 5     long long res = n, i;
 6     for(i = 2; i <= n; ++ i)
 7     {
 8         if(n % i == 0)
 9         {
10             res -= res / i;
11             while(n % i == 0)
12                 n /= i;
13         }
14     }
15     return res;
16 }
17 
18 int main()
19 {
20     long long n;
21     while(scanf("%lld",&n)&&n)
22     {
23         printf("%lld\n",MakePhi(n));
24     }
25     return 0;
26 }
View Code

 

posted @ 2013-08-24 23:01  Yours1103  阅读(119)  评论(0编辑  收藏  举报