-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (39 loc) · 940 Bytes
/
Copy pathmain.cpp
File metadata and controls
45 lines (39 loc) · 940 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
43
44
45
#include<iostream>
#include <vector>
class A{
private:
uint64_t _n;
std::vector<uint64_t> array;
public:
A(int n): _n(n) {};
std::vector<uint64_t> GetPriority() const{
std::vector<uint64_t> simple;
std::vector<bool> is_prime(_n+1, true);
is_prime[0] = is_prime[1] = false;
for(int i = 2; i * i <= _n; i++)
if (is_prime[i])
for (int j = i * i; j <= _n; j += i)
is_prime[j] = false;
for (int p = 2; p <= _n; p++)
{
if (is_prime[p])
{
simple.push_back(p);
}
}
return simple;
};
};
int main(){
uint64_t n;
std::cout << "Put number n: ";
std::cin >> n;
A array(n);
std::vector<uint64_t> prime = array.GetPriority();
for (int p : prime)
{
std::cout<< p << " ";
}
std::cout << std::endl;
return 0;
}