-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob7.cpp
More file actions
67 lines (57 loc) · 1.43 KB
/
prob7.cpp
File metadata and controls
67 lines (57 loc) · 1.43 KB
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
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <cstdint>
#include <cassert>
class primes_list
{
protected:
int* list;
int size = 0;
int upper = 10;
public:
int nth_prime;
primes_list(int n)
{
while (1)
{
upper *= 10;
list = new int[upper + 1];
for (int k = 0; k <= upper; k++)
{
if (k == 1)
list[k] = 0;
else
list[k] = k;
}
for (int p = 2; p <= upper; p++)
for (int j = p + p; j <= upper; j += p)
list[j] = 0;
for (int i = 0; i <= upper; i++)
if (list[i] != 0)
{
list[size] = list[i];
size++;
}
if (size < n)
{
size = 0;
delete list;
}
else
break;
}
nth_prime = list[n - 1];
}
~primes_list()
{
delete list;
}
};
int main(int argc, char *argv[])
{
primes_list foo = primes_list(10001);
std::cout << foo.nth_prime << std::endl;
return 0;
}