1181 prime number in prime number (prime number Sieve) topic Source: Sgu Base time limit: 1 second space limit: 131072 KB score: 0 Difficulty: Basic collection concern If a prime number is a primes, the numbers in the list are also prime numbers, so it is called prime numbers in prime numbers. 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 <bits/stdc++.h>
const int maxn=1e6+200;
using namespace std;
BOOL A[maxn]={false};
int main ()
{
long long n,i,j;
Long long ans=0;
cin>>n;
A[1]=true;
for (i=2; i<maxn; i++)
{
if (!a[i])
{
ans++;
if (!a[ans]&&i>=n)
{
cout<<i<<endl;
break;
}
for (j=i*i; j<maxn; j+=i)
a[j]=true;
}
}
return 0;
}