1181 prime numbers in prime numbers (prime number Sieve method)
Base time limit: 1 seconds space limit: 131072 KB If a prime number is a prime in a list of numbers, it is called prime in prime. For example: 3 5 are prime numbers for the 2nd and 3rd respectively, so they are prime numbers in prime numbers. Now give a number n, and find out how many prime numbers are in the smallest prime numbers of >=n (which can be considered by the prime sieve method). Input
Enter a number n (n <= 10^6)
Output
The output >=n the prime number in the smallest prime number.
Input example
20
Output example
31
#include <cstdlib>#include<map>#include<cstring>#include<iostream>intMain () {int*Is_prime; Is_prime= (int*)malloc(sizeof(int) *10010000); is_prime[0]= is_prime[1]=1; for(intI=2; i<10010000; i++) { if(!Is_prime[i]) for(intJ=i+i; j<10010000; j+=i) {is_prime[j]=1; }} std::map<int,int>m; intCnt=1; for(intI=1; i<=10010000; i++) { if(!Is_prime[i]) {M[i]= cnt++; } } intN; while(std::cin>>N) {intRec; for(intI=n;; i++) { if(!is_prime[i] &&!Is_prime[m[i]]) {Rec=i; Break; }} std::cout<< rec<<'\ n'; } Free(Is_prime); Is_prime=NULL; return 0;}
1181 prime numbers in prime numbers (prime number Sieve method)