1702: Find new friendsTime limit: 1 Sec memory limit: MB
Submissions: 16 Resolution: 7
The status of your title: Completed
Submitted State [Discussion Version]
Title DescriptionThe new year is coming, Tian Qin ready to engage in a party, already know the existing member N, the member from 1 to n number, where the president's number is N, and the president is an old friend, then the member's number and N has more than 1 of the convention number, otherwise are new friends, now the president wants to know how many new friends. Please make up the program gang length calculation.
inputThe first line is the number of groups of test data cn (case number,1<cn<10000), followed by a CN-line positive integer n (1<n<32768), representing the number of members.
OutputFor each n, the number of new friends is output, so there is a CN line output.
Sample Input
2
25608
24027
Sample Output
7680
16016
The Euler function can be used to calculate the number of (1~n-1) between the numbers and N coprime (that is, greatest common divisor is 1), the following code
#include <stdio.h> int T, n;
Euler function int eular (int n) {int ret = 1;
for (int i=2; i*i<=n; i++) if (n%i==0) {n/= i, ret *= i-1;
while (n%i==0) n/= i, ret *= i;
} if (n>1) ret *= n-1;
return ret;
} int main () {//Freopen ("Input.txt", "R", stdin);
scanf ("%d", &t);
while (t--) {scanf ("%d", &n);
The number of n-1 before solving is as many as N coprime printf ("%d\n", Eular (n));
} return 0; }