#P6068. 『MdOI R1』GCD? GCD!

『MdOI R1』GCD? GCD!

Problem Description

Ling likes gcd\mathrm{gcd}, that is, the greatest common divisor. If you do not know what the greatest common divisor is, you can visit Greatest Common Divisor - OI Wiki.

Ling gives you a positive integer nn and asks you to split it into the sum of three pairwise distinct positive integers a,b,ca, b, c, such that gcd(a,b,c)\mathrm{gcd}(a, b, c) is as large as possible.

Input Format

This problem has multiple test cases.

The first line contains a positive integer TT, which indicates the number of test cases.

The next TT lines each contain a positive integer nn.

Output Format

For each test case, output one integer per line, which is the answer, i.e., the maximum possible value of gcd(a,b,c)\mathrm{gcd}(a, b, c).

In particular, if nn cannot be written as the sum of three pairwise distinct positive integers, output -1.

3
12
27
5

2
3
-1

Hint

[Sample Explanation]

Split 1212 into 2+4+62 + 4 + 6. It can be proven that gcd(2,4,6)=2\gcd(2, 4, 6) = 2 is the maximum possible value.

Split 2727 into 3+6+183 + 6 + 18. It can be proven that gcd(3,6,18)=3\gcd(3, 6, 18) = 3 is the maximum possible value.

55 cannot be written as the sum of three pairwise distinct positive integers, so output -1.


[Constraints]

This problem uses bundled testdata.

Subtask ID nn \le Score
1 5050 17
2 500500 19
3 10510^5 23
4 10910^9 41

For 100%100\% of the testdata, 1T1001 \le T \le 100 and 1n1091 \le n \le 10^9.

Translated by ChatGPT 5