题意是:找一个数比他小的互质数,用欧拉函数
Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz.
Input
There are several test cases. For each test case, standard input contains a line with n <= 1,000,000,000. A line containing 0 follows the last case.
Output
For each test case there should be single line of output answering the question posed above.
Sample Input
7 12 0
Sample Output
6 4
代码:
#include <iostream>
using namespace std;
#include<stdio.h>
#include<string.h>
int d[100],k;
void f(int a)
{
int i,flag;
k=0;
for(i=2;a!=1;i++)
{
flag=0;
while(a%i==0)
{
flag=1;
d[k]=i;
a/=i;
}
if(flag)
k++;
}
}
int main()
{
int n,i,s;
while(scanf("%d",&n)!=EOF&&n!=0)
{
f(n);
for(i=0;i<k;i++)
{
s=0;
s+=(n-n/d[i]);
n=s;
}
printf("%d\n",s);
}
return 0;
}