We say that a positive integer nn is kk-good for some positive integer kk if nn can be expressed as a sum of kk positive integers which give kk distinct remainders when divided by kk.
Given a positive integer nn, find some k≥2k≥2 so that nn is kk-good or tell that such a kk does not exist.
Input
The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1051≤t≤105) — the number of test cases.
Each test case consists of one line with an integer nn (2≤n≤10182≤n≤1018).
Output
For each test case, print a line with a value of kk such that nn is kk-good (k≥2k≥2), or −1−1 if nn is not kk-good for any kk. If there are multiple valid values of kk, you can print any of them.
Example
input
Copy
5 2 4 6 15 20
output
Copy
-1 -1 3 3 5 思路 按照题意可知n与k(k+1)/2模k同余 可以把n分解为2的幂次乘于奇数(p * q) 观察发现当k = 2*p 或 k = q 时满足条件 又因为n >= k(k+1)/2 当k = 2*p 时有 q >= 2*p + 1 当k = q 时有2*p >= q + 1
所以取min(2*p,q)即可 又因为k >= 2 所以q = 1 不满足条件
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve() {
ll n,k = 1;
cin >> n;
while(n % 2 == 0){
n /= 2;
k *= 2;
}
if(n == 1){
cout << "-1" << "\n";
}
else{
cout << min(n,2*k) << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T;
cin >> T;
while(T--) {
solve();
}
return 0;
}