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.