POJ 1284

这题用了初等数论的原根和欧拉函数的知识。

http://zh.wikipedia.org/wiki/%E5%8E%9F%E6%A0%B9上面介绍的很详细。

其他的,没什么难度了。

View Code
 1 #include<iostream>

 2 #include<cstdio>

 3 using namespace std;

 4 

 5 int main()

 6 {

 7     int p;

 8     while (~scanf("%d",&p)) {

 9         int ind(p-1),ans(p-1),temp(1);

10         for (int i(2); i<=ind; ++i) {

11             if (ind%i == 0) {

12                 temp *= i;

13                 ans *= (i-1);

14                 while (ind%i == 0)ind /= i;

15             }

16         }

17         ans = ans/temp;

18         cout<<ans<<endl;

19     }

20 }

你可能感兴趣的:(poj)