http://poj.org/problem?id=2407
题意:
给出一个n,求小于等于的n的数中与n互质的数有几个。
思路:
欧拉函数的作用就是用来求这个的。
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
using namespace std; int n; int main()
{
//freopen("D:\\txt.txt", "r", stdin);
while (cin >> n && n)
{
double ans = ;
int x = n;
if (n == )
cout << "" << endl;
else
{
for (int i = ; i <= n; i++)
{
if (n%i == )
{
x = x - x / i;
while (n%i == )
n /= i;
}
}
if (n > )
x = x - x / n;
}
cout << x << endl;
}
}