Prime Number
[Creator : Imported]
Time Limit : 1.000 sec Memory Limit : 32 MB
Description
Output the k-th prime number.
Input
k≤10000
Output
The k-th prime number.
Sample Input Copy
10
50
Sample Output Copy
29
229
#include <stdio.h>
#include <math.h>
bool isPrime(int a)
{
if(a<=1) return false;
int fin=sqrt(a);
for(int i=2;i<=fin;i++)
{
if(a%i==0) return false;
}
return true;
}
const int max=110000;
int Prime[max];
int x=1;
bool p[max]={false};
int m,n;
void isPrime2()
{
for(int i=2;i<max;i++)
{
if(p[i]==false)
{
Prime[x++]=i;
for(int j=i*2;j<max;j+=i)
p[j]=true;
}
}
}
int main()
{
isPrime2();
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",Prime[n]);
}
}