NK_1214: Relatives
2011-05-22 09:08 Min·zc 阅读(183) 评论(0) 编辑 收藏 举报
1 /*
2 *今天看了一下欧拉函数,找了个水题练了一下
3 *
4 */
5
6
7 #include <iostream>
8 using namespace std;
9 int eular(int n)
10 {
11 int ret=1;
12 for(int i=2;i*i<=n;i++)
13 {
14 if(n%i==0)
15 {
16 ret*=(i-1);
17 n/=i;
18 while(n%i==0)
19 {
20 n/=i;
21 ret*=i;
22 }
23 }
24 // if(n<i)
25 // break;
26 }
27 if(n>1)
28 ret*=(n-1);
29 return ret;
30
31 }
32 int main()
33 {
34 int t;
35 while(cin>>t,t!=0)
36 {
37 cout<<eular(t)<<endl;
38 }
39 }
2 *今天看了一下欧拉函数,找了个水题练了一下
3 *
4 */
5
6
7 #include <iostream>
8 using namespace std;
9 int eular(int n)
10 {
11 int ret=1;
12 for(int i=2;i*i<=n;i++)
13 {
14 if(n%i==0)
15 {
16 ret*=(i-1);
17 n/=i;
18 while(n%i==0)
19 {
20 n/=i;
21 ret*=i;
22 }
23 }
24 // if(n<i)
25 // break;
26 }
27 if(n>1)
28 ret*=(n-1);
29 return ret;
30
31 }
32 int main()
33 {
34 int t;
35 while(cin>>t,t!=0)
36 {
37 cout<<eular(t)<<endl;
38 }
39 }