题解 | #Prime Number#
Prime Number
https://www.nowcoder.com/practice/c5f8688cea8a4a9a88edbd67d1358415
#include <iostream> using namespace std; const int N=10010; int a[N]; bool is_prime(int n){ for(int i=2;i<=n/i;i++) if(n%i==0) return false; return true; } int main() { //预处理,存储10000个素数 int index=0; int num=2; while(index<10000){ if(is_prime(num)) a[index++]=num; num++; } int k; while(cin>>k){ cout<<a[k-1]<<endl; } return 0; }