-
Notifications
You must be signed in to change notification settings - Fork 0
/
Seive.code-snippets
38 lines (38 loc) · 968 Bytes
/
Seive.code-snippets
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
{
"Seive": {
"prefix": "Seive",
"body": [
"template < typename T = int > struct Seive {",
"",
" vector < bool > is_prime;",
" vector < T > primes;",
"",
" Seive(int n){",
" is_prime.assign(n + 1, true);",
" is_prime[0] = is_prime[1] = false;",
" for(ll i = 2; i <= sqrt(n); i++)",
" if(is_prime[i])",
" for(ll j = i * i; j <= n; j += i) is_prime[j] = false;",
" }",
"",
" // Build vector with prime numbers",
"",
" void get_primes(int n){",
" for(int i = 1; i <= n; i++)",
" if(is_prime[i])",
" primes.push_back(i);",
" }",
"",
" // Print the prime numbers",
"",
" void print_primes(){",
" for(auto& p : primes)",
" cout << p << \" \";",
" cout << \"\\n\";",
" }",
"",
"};"
],
"description": "Seive"
}
}