-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathB.cpp
52 lines (38 loc) · 923 Bytes
/
B.cpp
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
#include <iostream>
#include <vector>
#include <algorithm>
const int INF = 1000000 + 5;
int n;
std::vector<long long> prime;
void eratosthenesSieve() {
prime.assign(INF + 1, true);
for (long long i = 0; i < prime.size(); ++i) {
prime[i] = i;
}
for (long long i = 2; i <= INF; ++i)
if (prime[i] == i)
for (long long j = i * i; j <= INF; j += i)
prime[j] = i;
}
std::vector<long long> factorization(long long x) {
std::vector<long long> res;
while (x != 1) {
res.push_back(prime[x]);
x /= prime[x];
}
std::sort(res.begin(), res.end());
return res;
}
int main() {
scanf("%d", &n);
eratosthenesSieve();
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
for (long long p : factorization(x)) {
printf("%lld ", p);
}
printf("\n");
}
return 0;
}