Hduoj 1286 Find new friends

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.