-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimefactor.cpp
More file actions
72 lines (56 loc) · 1.34 KB
/
primefactor.cpp
File metadata and controls
72 lines (56 loc) · 1.34 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
#include <bits/stdc++.h>
using namespace std;
#define MAINRET(x) in##x
#define what_is(x) cout << #x << " is " << x << endl;
#define LL long long
#define arr array<int,2>
void solve();
MAINRET(t) main(void) {
std::cin.tie(nullptr);
std::cin.sync_with_stdio(false);
solve();
}
constexpr int INF = std::numeric_limits<int>::max() / 2;
constexpr int NINF = -INF;
constexpr LL MX = 3 * 1e5;
constexpr int MD = (int)1e9 + 7;
int n, m, k;
int a, b;
void solve() {
// PREPROCESSING SIEVE
constexpr int LIM = (int)1e5;
vector<int> is_p(LIM+1, true);
vector<int> primes;
is_p[0] = is_p[1] = false;
for (int i = 2; i*i <= LIM; i++) {
if (is_p[i]) {
for (int j = i*i; j <= LIM; j += i) {
is_p[j] = false;
}
}
}
for (int i = 2; i <= LIM; i++) {
if (is_p[i]) primes.push_back(i);
}
// TAKE INPUT
cin >> a >> b;
vector<int> fact1, fact2;
for (auto pr : primes) {
if (pr * pr > a) break;
while (a % pr == 0) {
fact1.push_back(pr);
a /= pr;
}
}
if (a > 1) fact1.push_back(a);
for (auto pr : primes) {
if (pr * pr > b) break;
while (b % pr == 0) {
fact2.push_back(pr);
b /= pr;
}
}
if (b > 1) fact2.push_back(b);
}
/*
*/