就是判断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;
}