Find new friends
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 10401 Accepted Submission (s): 5493
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 Input22560824027
Sample Output768016016
Authorsmallbeer (CML)
SOURCE Hangzhou Electric ACM Training Team Training Tournament (VII)
Recommendlcy | We have carefully selected several similar problems for you:1215 1406 1164 1787 1211
I represent prime numbers non-prime numbers not running res representing the remainder is the number of answers x represents the number of mass factor decomposition from x decomposition of the mass factor to use
Run out of 2 to remove the multiples of 2 so there is a while that sentence.
#include <iostream>#include<stdlib.h>#include<stdio.h>#include<algorithm>#include<string.h>#include<math.h>using namespacestd;intEulerintx) {//is the formula .intI, res=x; for(i =2; I < (int) sqrt (x *1.0) +1; i++)if(x%i==0) {cout<<"START I:"<<i<<"Res:"<<res<<"x:"<<x<<Endl;res= res/i * (i-1); cout<<"Delete I:"<<i<<"Res:"<<res<<"x:"<<x<<Endl; while(x% i = =0) {x/= i;cout<<"x%i==0 I:"<<i<<"Res:"<<res<<"x:"<<x<<endl;}//Guarantee I must be a prime numbercout<<Endl;}if(X >1) {res = res/x * (X-1);cout<<"End I:"<<i<<"Res:"<<res<<"x:"<<x<<Endl;}returnRes;}intMain () {intn,t; CIN>>T; while(t--) {cin>>N; cout<<euler (n) <<Endl;} return 0;}
HDU1286 New friend Euler function edition