您的位置:首页 > 其它

284A. Cows and Primitive Roots

2013-03-19 02:20 169 查看
A. Cows and Primitive Roots

time limit per test
2 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

The cows have just learned what a primitive root is! Given a prime p, a primitive root 

 is
an integer x (1 ≤ x < p) such that none
of integers x - 1, x2 - 1, ..., xp - 2 - 1 are
divisible by p, but xp - 1 - 1 is.

Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime p, help the cows find the number of primitive roots 

.

Input

The input contains a single line containing an integer p (2 ≤ p < 2000).
It is guaranteed that p is a prime.

Output

Output on a single line the number of primitive roots 

.

Sample test(s)

input
3


output
1


input
5


output
2


Note

The only primitive root 

 is 2.

The primitive roots 

 are 2 and 3.

简单的模拟题~~~直接进行模拟就好了~~~

就是判断modP后的个数~~~

注意2的情况就可以了。

post code:

#include<stdio.h>
#include<string.h>
int cal(int max){ //求满足条件的个数
int i,sum=0,j,k,da;
for(k=1;k<max;k++){ //要从1开始遍历 注意当输入为2的情况
da=k;
int flag=1;
for(j=1;j<max-1;j++){
if( (da-1)%max==0 ){flag=0;break;}
else da=da*k%max;
}
if((flag==1)&&((da-1)%max==0))sum++;
}
return sum;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
printf("%d\n",cal(n));

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  算法