Prime Number
TimeLimit: 1 Second MemoryLimit: 32 Megabyte
Totalsubmit: 399 Accepted: 88
Description
We know that the number of prime numbers is countless. Now we want to know the kth small prime number.
Input
Input contains multiple test cases. Each test case contains an integer k.(1<=k<=10^5)
Output
Print the kth small prime number.
Sample Input
1
2
4
Sample Output
2
3
7
#include <iostream> #include <stdio.h> #include <math.h> #include <string.h> #define maxn 10000000 using namespace std; ]; ]; int num; void fun() { int limt=sqrt(maxn+0.0); int i,j; num=; pre[num++]=; memset(p,,sizeof(p)); ;i<=maxn;i+=)p[i]=; ;i<=limt;i+=) { if(p[i])continue; pre[num++]=i; ; } for(;i<=maxn;i++)if(!p[i])pre[num++]=i; } int main() { //freopen("in.txt","r",stdin); fun(); int n; while(cin >> n) { cout << pre[n-] << endl; } ; }