forked from DionysiosB/CodeForces
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1366D-TwoDivisors.cpp
More file actions
43 lines (36 loc) · 1.04 KB
/
Copy path1366D-TwoDivisors.cpp
File metadata and controls
43 lines (36 loc) · 1.04 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
#include <cstdio>
#include <vector>
int main(){
const long B = 1e7 + 9;
std::vector<bool> v(B, 1);
v[0] = v[1] = 0;
for(long p = 2; p * p <= B; p++){
if(!v[p]){continue;}
for(long q = 2 * p; q < B; q += p){v[q] = 0;}
}
std::vector<long> w;
for(long p = 0; p < B; p++){
if(!v[p]){continue;}
w.push_back(p);
}
long n; scanf("%ld", &n);
std::vector<long> a(n, -1), b(n, -1);
for(long p = 0; p < n; p++){
long x; scanf("%ld", &x);
std::vector<long> f;
for(long y : w){
if(y * y > x){break;}
if(x % y){continue;}
if(f.size() < 2){f.push_back(y);}
else{f.back() *= y;}
while(x % y == 0){x /= y;}
}
if(x > 1){
if(f.size() < 2){f.push_back(x);}
else{f.back() *= x;}
}
if(f.size() > 1){a[p] = f[0]; b[p] = f[1];}
}
for(long p = 0; p < n; p++){printf("%ld ", a[p]);}; puts("");
for(long p = 0; p < n; p++){printf("%ld ", b[p]);}; puts("");
}