http://acm.hdu.edu.cn/showproblem.php?pid=1286
Find new Friends
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 8694 Accepted Submission (s): 4592
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
Analysis:
The topic requires finding all integers that are less than N and N-intertextuality (including 1 not including N).
Sieve method for Prime Orz
AC Code:
1#include <stdio.h>2#include <string.h>3 intjudge[40000];4 intMain ()5 {6 intN, M;7 intans;8scanf"%d", &n);9 while(n--)Ten { One intCNT =0; Ascanf"%d", &m); -memset (judge,0,sizeof(judge)); - for(inti =2; I <= m/2; i++) the { - if(m%i = =0) - { -Judge[i] =1; + for(intj = i; J <= M; j+=i) -JUDGE[J] =1; + } A } at for(inti =2; I < m; i++){ - if(Judge[i] = =0){ -cnt++; - } - } -printf"%d\n", CNT +1); in } - to return 0; +}
Hduoj 1286 Find new friends