Two Divisors【GCD数论】

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给做到gcd(d1 + d2, a_i) == 1,然后这里用一下公式gcd(x, y) == 1则有gcd(x + y, x * y) == 1。(可以用反证法,假设存在,然后反证。)

  然后我们可以找到第一个质因子为p,然后为了保证gcd(x, y) == 1然后我们把a[i]的所有的p都给d1,然后剩下的就是d2了,只要d2不为1,那么就是有解了。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#include 
//#include 
#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 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 ans[maxN];
pair solve(int x)
{
    pair s = make_pair(-1, -1);
    int len = (int)Prim.size();
    for(int i=0; i

 

你可能感兴趣的:(数论)