HDU-1268 find new friends (prime screening)

Source: Internet
Author: User

Find new friends

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 2518 accepted submission (s): 1183

Problem description the New Year is approaching. The pig Association is preparing to have a party. We already know that there are n members and the number of members ranges from 1 to n. The number of the President is N, if you are an old friend of the president, the member's number must have an appointment with N greater than 1. Otherwise, they will all be new friends. Now the president wants to know how many new friends there are? Compile a program to help the President calculate it.

The first line of input is the number of test data groups CN (case number, 1 <CN <10000), followed by a positive integer N (1 <n <32768) in CN, indicating the number of members.

Output outputs the number of new friends in a row for each n, so that a total of CN rows are output.

Sample Input

22560824027
 

Sample output

768016016
 

Authorsmallbeer (CRF)

In particular, the limit cannot be located in SQRT (x) when the approximate number is obtained, but it should be X itself, because it is to find all its prime numbers.

The Code is as follows:

#include<stdio.h>#include<stdlib.h>#include<math.h>#include<string.h>#include<time.h>int T;bool Is( int x ){    int sum=0;    for( int i=1 ;i< x;++i )        if( !(x%i) )            sum+=i;    if( sum==x )        return true;    else        return false;}int main(){    scanf( "%d" ,&T );    while(T--)    {        int a,b,cnt=0;        scanf( "%d%d" ,&a,&b );        if( a>b )            a^=b^=a^=b;        for( int i=a ;i<=b;++i )            if( Is( i ) )                cnt ++;        printf( "%d\n" ,cnt );    }    return 0;}


The idea is to find an appointment with a number greater than 2, and then find their multiples in sequence, and add this factor to the subscript array of their multiples.

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.