http://acm.hdu.edu.cn/showproblem.php?pid=1787

依然是欧拉函数的模板题,求有多少个小于等于N且不与N互质的数,减去N本身再减去和N互质的就好了,小于N且和N互质的数的个数就用欧拉函数算了

View Code
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
int Eular(int n)
{
    int ret=n;
    for(int i=2;i*i<=n;i++)
        if(n%i==0)
        {
            ret-=ret/i;
            while(n%i==0)n/=i;
            if(n==1)break;
        }
    if(n!=1)ret-=ret/n;
    return ret;
}
int main()
{
    int n;
    while(scanf("%d",&n),n)
        printf("%d\n",n-1-Eular(n));
    return 0;
}