Coach Yu has lots of bags, every bag has its number. And what is more, he wants to send these bags to acm team-member. But he requires that if you get the bag and its number is b, you need to count how many number smaller than b and co-prime with b. If you can't count it, he won't send the bag to you.
However, G.D.R and Hacb learn the The Euler function to solve the problem. And they are so friendly that they like to share the function to you, so you can get the bag.
The Euler function is:
F(b) = b *( 1 - 1/p1) ( 1 - 1/p2)......(1-1/pn)
Notes: pi is the ith Prime factors of b, and there will be no such i and j which i<>j but pi=pj.
Input
A number b as describe . 0
Output
Output F(b) on a line.
If n=1, you should just output 0.
Sample Input
7
0
Sample Output
6
Hint: f(7) = 7 * (1 - 1/7) = 6
欧拉函数
#include
#include
using namespace std;
#define LL long long
int main()
{
long long n;
while(cin>>n&&n)
{
long long temp=n;
long long ans=n;
for(long long i=2;i*i<=temp;i++)
{
if(temp%i==0)
{
ans=(ans-ans/i);
while(temp%i==0)
{
temp=temp/i;
}
}
}
if(temp!=1)
ans=(ans-ans/temp);
printf("%lld\n",ans);
}
return 0;
}