284A. Cows and Primitive Roots

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;
}








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值