|
|
back to boardMY SOLUTION! #include<iostream> #include<vector> using namespace std; vector<int>a; bool is_prime (int n) { if (n<=1) return 0; if (n==2) return true; if (!(n%2)) return false; for (int i=2;i*i<=n;i++) if (!(n%i)) return 0; return 1; } void primes () { a.push_back(2); int i=3,br=1; for (;br<15001;i+=2) if (is_prime(i)) {br++;a.push_back(i);} } int main () { int n,k; primes(); cin>>n; for (int i=0;i<n;i++) {scanf("%d",&k);printf("%d\n",a[k-1]);} return 0; } |
|
|