-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpfactorize_range.cpp
More file actions
47 lines (40 loc) · 838 Bytes
/
pfactorize_range.cpp
File metadata and controls
47 lines (40 loc) · 838 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
46
47
const int N = 1e2 + 7;
bool composite[N];
int LargestPrime[N];// {0} initially all prime and stores the largest prime factor of indexed number
vector<pair<int, int>> pf[N + 5];// stores pfactorization
void sieve() {
for (int i = 2; i <= (N); i++) {
if (composite[i]) continue;
LargestPrime[i] = i;
for (int j = i * i; j <= N; j += i) {
LargestPrime[j] = i;
composite[j] = 1;
}
}
}
void pfactorize() {
for (int i = 2; i <= N; i++) {
int x = i;// pfactorize i
map<int, int> mp;
while (x != 1) {
mp[LargestPrime[x]]++;
x /= LargestPrime[x];
}
for (auto v : mp) {
pf[i].push_back(v);// prime, exponent
}
}
}
void solve() {
sieve();
pfactorize();
}
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("error.txt", "w", stderr);
#endif
crap;
solve();
return 0;
}