HDU 1787 GCD Again

时间:2022-02-13 15:50:42

题目大意:求小于n的gcd(i,n)大于1的个数;

题解:欧拉函数直接求gcd(i,n)==1的个数  用n减即可

#include <cstdio>
int eular(int n){
int ret=1,i;
for(i=2;i*i<=n;i++)
if(n%i==0){
n/=i,ret*=i-1;
while(n%i==0)n/=i,ret*=i;
}
if(n>1) ret*=n-1;
return ret;
}
int main(){
int n;
while(scanf("%d",&n),n!=0)printf("%d\n",n-eular(n)-1);
return 0;
}