-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nth prime.cpp
58 lines (34 loc) · 885 Bytes
/
Nth prime.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
using namespace std;
#define MAX_SIZE 1000005
void SieveOfEratosthenes(vector<int> &primes)
{
bool IsPrime[MAX_SIZE];
memset(IsPrime, true, sizeof(IsPrime));
for (int p = 2; p * p < MAX_SIZE; p++)
{
if (IsPrime[p] == true)
{
for (int i = p * p; i < MAX_SIZE; i += p)
IsPrime[i] = false;
}
}
for (int p = 2; p < MAX_SIZE; p++)
if (IsPrime[p])
primes.push_back(p);
}
int main()
{
vector<int> primes;
int a,b;
cin >> a >> b;
SieveOfEratosthenes(primes);
for (int i = 0; i < a; i++){
if(i != 0){
cout << primes[(i*b)] << "\n";
}
else{
cout << primes[i] << "\n";
}
}
}