-
Notifications
You must be signed in to change notification settings - Fork 0
/
Two Divisors CODEFORCES SEIVE
77 lines (74 loc) · 1.63 KB
/
Two Divisors CODEFORCES SEIVE
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
67
68
69
70
71
72
73
74
75
76
77
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
const int mod=1e9+7;
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define clr(a,x) memset(a,x,sizeof(a))
#define T int t;cin>>t; while(t--)
#define vll vector<int>
#define v22 vactor<vector<int>>
#define pb push_back
#define sz size
#define str to_string
#define um unordered_map<int,int>
#define intt stoll
#define sv() sort(a.begin(),a.end())
#define vp vector<pair<int, int>> b(n)
vll p(1e7 + 1, 1);
void seive()
{
for (int i = 2; i * i <= 1e7; i++)
if (p[i] == 1)
for (int j = i * i; j <= 1e7; j += i)
if (p[j] == 1) p[j] = i;
}
int32_t main(){
seive();
int n,x=0,d1=1,d2=1;
cin>>n;
vll a(n);
for(int i=0;i<n;i++)
cin>>a[i];
vector<pair<int,int>> b(n);
for(int i=0;i<n;i++)
{
x=a[i],d1=1,d2=1;
int m=0;
if(p[x]==1)
{
b[i].first=-1;
b[i].second=-1;
}
else if(p[x]!=1)
{
while (p[x] != 1)
{
if (d1 == 1)
d1 = p[x];
else
d2 *= p[x];
m = p[x];
while (x % m == 0)
x = x / m;
}
d2=d2*x;
// cout<<d1<<" "<<d2<<" "<<a[i]<<endl;
if(d1==1 || d2==1)
{
b[i].first=-1;
b[i].second=-1;
}
else
{
b[i].first=d1;
b[i].second=d2;
}
}
}
for(int i=0;i<n;i++)
cout<<b[i].first<<" ";
cout<<endl;
for(int i=0;i<n;i++)
cout<<b[i].second<<" ";
}