“Goodbye to the friends I’ve had, goodbye to my upstairs neighbor, goodbye to the kids downstairs, and anybody who lend me a favor.”
“Or, goodbye to the positive proper divisor?”
That game is popular these days. Two player take turns to choose a specific number and claim it. The player who takes the first turn chooses one positive proper divisor of given n. In the next rounds, player should choose one positive proper divisor (真因数) of the number claimed in the previous round. The player who can’t make a choice will win.
Formally, a positive proper divisor of n is a divisor of n, and it cannot be either 1 or n.
Now Chino is going to play this game with David. Chino always wants to win and meanwhile she wants to keep the chosen number as big as possible. If with the given n, Chino will win directly or fail anyway, you should also tell her.
Can you help Chino to choose her answer in the first round?
Input
The first line contains one integer T (1≤T≤103) denoting the count of testcases.
For each testcase, one line with one integer n (1≤n≤105) denoting the given n in one game.
Output
For each testcase, you should output the biggest choice, or 0 when Chino will win directly, or −1 when Chino will fail anyway.
Example
Input
4
3
4
8
666
Output
0
-1
4
111
#include <bits/stdc++.h>
using namespace std;
bool vis[100005] = {0};
int prime[100005];
int k = 0;
void get_prime() { //存入素数
int i, j;
memset(vis, 0, sizeof(vis));
vis[1] = 1;
for (i = 2; i < 100000; i++) {
if (vis[i] == 0) {
for (j = i * 2; j < 100000; j += i) {
vis[j] = 1;
}
prime[k++] = i;
}
}
}
int main() {
get_prime();
int t, n, m, i, j, s, sum, ans;
int a[100004], b[100004];
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
if (n == 1) {
printf("0\n");
continue;
}
m = n;
j = 0;
sum = 0;
for (i = 0; i < k; i++) { //将n的素数因子存入a[],将对应的因数个数存入b[]
s = 0;
while (m % prime[i] == 0) {
m /= prime[i];
s++;
if (m == 1) break;
}
if (s) {
a[j] = prime[i];
b[j++] = s;
sum += s;
}
if (m == 1) break;
}
if (sum < 2)
printf("0\n");
else if (sum == 2)
printf("-1\n");
else { //使剩余数为两个最大素数因子的乘积,就能必赢,而且值尽可能最大
if (b[j - 1] == 1)
ans = a[j - 1] * a[j - 2];
else
ans = a[j - 1] * a[j - 1];
printf("%d\n", ans);
}
}
return 0;
}