Find a new friend time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 9382 accepted Submission (s): 4969
Problem Description The New Year is coming, "Pig Head Help Association" ready to engage in a party, already know the existing member N people, the membership from 1 to n number, where the president's number is N, and the president is an old friend, then the member's number affirmation and n have more than 1 of the convention number, otherwise are new friends , now the president wants to know how many new friends there are. Please compile the program gang length to calculate it.
Input the first line is the number of test data of the group CN (case number,1<cn<10000), followed by the CN line positive integer n (1<n<32768), indicating the number of members.
Output for each n, the number of new friends out of a row, so that a total of CN line output.
Sample Input
2 25608 24027
Sample Output
7680 16016
Author Smallbeer (CML)
Source Hangzhou Electronic ACM Team Training Competition (VII)
Recommend the most conventional Euler function, do not make redundant explanations, in Baidu find the most concise function template.
#include <stdio.h>
int n,t;
int ou (int n)
{
int ret=1,i;
for (i=2;i*i<=n;i++)
{
if (n%i==0)
{
n=n/i;
RET =ret* (i-1);
while (n%i==0)
{
n=n/i;
Ret=ret*i
}
}} if (n>1) return
ret* (n-1);
else return
ret;
}
int main ()
{
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &n);
printf ("%d\n", OU (n));
}
return 0;
}