-
题目描述:
-
Output the k-th prime number.
-
输入:
-
k≤10000
-
输出:
-
The k-th prime number.
-
样例输入:
-
3 7
-
样例输出:
-
5 17
#include<iostream> #include<cmath> using namespace std; int prime[10001]={0}; int size=0; bool judge(int x){ if(x<=1) return false; int b=(int)sqrt(x)+1; for(int i=2;i<b;i++){ if(x%i==0) return false; } return true; } void init(){ int i=2; while(size<=10000){ if(judge(i)==true) prime[size++]=i; i++; } } int main(){ int n; init(); while(cin>>n){ cout<<prime[n-1]<<endl; } return 0; }