Find new friendsTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 9383 Accepted Submission (s): 4970
Problem description New Year is coming, "pig head to help the association" 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 affirmation and N has more than 1 of the convention number, otherwise are new friends , now the president wants to know how many new friends there are? Please make up the program gang length calculation.
The first line of input 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.
Output for each n, the number of new friends out of a line, so that a total of CN line output.
Sample Input
22560824027
Sample Output
768016016 Code:#include <stdio.h>int E (int n) {int a=n,res=n;for (int i=2;i*i<=a;i++) {if (a%i==0) {res=res/i* (i-1);// Divide first to prevent intermediate data overflow;}while (a%i==0) {a=a/i;}} if (a>1) {res=res/a* (A-1);} return res;} int main () {int t,n;scanf ("%d", &t), while (t--) {scanf ("%d", &n);p rintf ("%d\n", E (n));} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Hdoj 1286 Find new friends