-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNum.cpp
More file actions
42 lines (41 loc) · 806 Bytes
/
PrimeNum.cpp
File metadata and controls
42 lines (41 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <cstdio>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
vector<int> prime;
int judge(int x)
{
int limit = sqrt(x);
for (int i = 2; i <= limit; i++)
{
if (x % i == 0)
{
return 0;
}
}
return 1;
}
int main(int argc, char const *argv[])
{
for (int i = 2; i < 120000; i++)
{
if (judge(i) == 1)
{
// cout << i << " ";
prime.push_back(i);
}
}
// cout << endl;
// for (int i = 0; i < prime.size(); i++)
// {
// cout << prime[i] << " ";
// }
int k;
while (cin >> k) // 第k个质数,序号是k-1
{
cout << prime[k - 1] << endl;
}
return 0;
}