You are given nn integers a1,a2,…,ana1,a2,…,an.
For each aiai find its two divisors d1>1d1>1 and d2>1d2>1 such that gcd(d1+d2,ai)=1gcd(d1+d2,ai)=1 (where gcd(a,b)gcd(a,b) is the greatest common divisor of aa and bb) or say that there is no such pair.
Input
The first line contains single integer nn (1≤n≤5⋅1051≤n≤5⋅105) — the size of the array aa.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (2≤ai≤1072≤ai≤107) — the array aa.
Output
To speed up the output, print two lines with nn integers in each line.
The ii-th integers in the first and second lines should be corresponding divisors d1>1d1>1 and d2>1d2>1 such that gcd(d1+d2,ai)=1gcd(d1+d2,ai)=1 or −1−1 and −1−1 if there is no such pair. If there are multiple answers, print any of them.
有N个值(其实可以看成T组输入),然后求每一个a[i]能否被两个它的除数d1, d2给做到,然后这里用一下公式则有。(可以用反证法,假设存在,然后反证。)
然后我们可以找到第一个质因子为p,然后为了保证然后我们把a[i]的所有的p都给d1,然后剩下的就是d2了,只要d2不为1,那么就是有解了。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <limits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
//#include <unordered_map>
//#include <unordered_set>
#define lowbit(x) ( x&(-x) )
#define pi 3.141592653589793
#define e 2.718281828459045
#define INF 0x3f3f3f3f
#define HalF (l + r)>>1
#define lsn rt<<1
#define rsn rt<<1|1
#define Lson lsn, l, mid
#define Rson rsn, mid+1, r
#define QL Lson, ql, qr
#define QR Rson, ql, qr
#define myself rt, l, r
using namespace std;
typedef unsigned long long ull;
typedef unsigned int uit;
typedef long long ll;
const int maxN = 5e5 + 5;
vector<int> Prim;
bool vis[10005] = {false};
void init()
{
for(int i=2; i<=10000; i++)
{
if(!vis[i])
{
Prim.push_back(i);
for(int j = 2 * i; j <= 10000; j += i) vis[j] = true;
}
}
}
int N, a[maxN];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
pair<int, int> ans[maxN];
pair<int, int> solve(int x)
{
pair<int, int> s = make_pair(-1, -1);
int len = (int)Prim.size();
for(int i=0; i<len; i++)
{
if(x % Prim[i] == 0)
{
int d1 = Prim[i];
x /= Prim[i];
while(x % Prim[i] == 0)
{
x /= Prim[i];
d1 *= Prim[i];
}
if(x == 1) return s;
s = make_pair(d1, x);
return s;
}
}
return s;
}
int main()
{
init();
scanf("%d", &N);
for(int i=1; i<=N; i++) scanf("%d", &a[i]);
for(int i=1; i<=N; i++) ans[i] = solve(a[i]);
for(int i=1; i<=N; i++) printf("%d%c", ans[i].first, i == N ? '\n' : ' ');
for(int i=1; i<=N; i++) printf("%d%c", ans[i].second, i == N ? '\n' : ' ');
return 0;
}