C++ 代码
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 1e4 + 1;
int ans[N];
bool is_prime(int x)
{
for (int i = 2; i <= sqrt(x); i++)
{
if (x % i == 0) return 0;
}
return 1;
}
int main()
{
ans[1] = 2;
int idx = 2, k;
for (int i = 3; ; i++)
{
if (is_prime(i)) ans[idx++] = i;
if (idx > 10000) break;
}
while (cin >> k)
printf("%d\n", ans[k]);
return 0;
}