-
Notifications
You must be signed in to change notification settings - Fork 0
/
Factors.code-snippets
47 lines (47 loc) · 1.2 KB
/
Factors.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
39
40
41
42
43
44
45
46
47
{
"Factors": {
"prefix": "Factors",
"body": [
"struct Factorization {",
" ",
" int n;",
" vector < int > factors;",
" vector < int > prime_factors;",
"",
" Factorization(int N){",
" n = N;",
" factors.assign(n + 10, 2);",
" prime_factors.resize(n + 10);",
" }",
"",
" // Get the number of factors for each number",
"",
" void factorization(int n){ ",
" for (ll i = 2; i <= n; i++) { ",
" for (ll j = i * 2; j <= n; j += i) factors[j]++;",
" }",
" }",
"",
" ll get_factors(ll n){",
" return factors[n];",
" }",
"",
" // Get the number of prime factors for each number",
"",
" void prime_factorization(int n){",
" for (ll i = 2; i <= n; i++){ ",
" if (!prime_factors[i]) { ",
" for (ll j = 2 * i; j <= n; j += i) prime_factors[j]++;",
" prime_factors[i] = 1; ",
" }",
" }",
" }",
"",
" ll get_prime_factors(ll n){",
" return prime_factors[n];",
" }",
"};"
],
"description": "Factors"
}
}