标签:ini namespace sqrt put code turn clu microsoft prim
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; }
标签:ini namespace sqrt put code turn clu microsoft prim
原文地址:https://www.cnblogs.com/bernieloveslife/p/9736519.html