CF BUDDY
← Problems·

1366D · Two Divisors

2000 · constructive algorithms, math, number theory

Problem: You are given nn integers a1,a2,,ana_1, a_2, \dots, a_n.

For each aia_i find its two divisors d1>1d_1 > 1 and d2>1d_2 > 1 such that gcd(d1+d2,ai)=1\gcd(d_1 + d_2, a_i) = 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 Format: The first line contains single integer nn (1n51051 \le n \le 5 \cdot 10^5) — the size of the array aa.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (2ai1072 \le a_i \le 10^7) — the array aa.

Output Format: 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>1d_1 > 1 and d2>1d_2 > 1 such that gcd(d1+d2,ai)=1\gcd(d_1 + d_2, a_i) = 1 or 1-1 and 1-1 if there is no such pair. If there are multiple answers, print any of them.

Note: Let's look at a7=8a_7 = 8. It has 33 divisors greater than 11: 22, 44, 88. As you can see, the sum of any pair of divisors is divisible by 22 as well as a7a_7.

There are other valid pairs of d1d_1 and d2d_2 for a10=24a_{10}=24, like (3,4)(3, 4) or (8,3)(8, 3). You can print any of them.

Sample Cases

Case 1

Input

10
2 3 4 5 6 7 8 9 10 24

Output

-1 -1 -1 -1 3 -1 -1 -1 2 2 
-1 -1 -1 -1 2 -1 -1 -1 5 3

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback