CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes)

PROMBLE D:K-good

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

Note

66 is a 33-good number since it can be expressed as a sum of 33 numbers which give different remainders when divided by 33: 6=1+2+36=1+2+3.

1515 is also a 33-good number since 15=1+5+915=1+5+9 and 1,5,91,5,9 give different remainders when divided by 33.

2020 is a 55-good number since 20=2+3+4+5+620=2+3+4+5+6 and 2,3,4,5,62,3,4,5,6 give different remainders when divided by 55.

我看了题解还是不是很懂,后来问学长了。

具体步骤我写在草稿纸上

rt:

两个特殊情况,奇数,奇数很简单,就是2。

2的幂次,算出来会是1,反正就不行

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1005;
priority_queue<int,vector<int>,greater<int>>pque;
int t;
bool isPowerOfTwo(ll n)
{
    return n > 0 && (n & (n - 1)) == 0;
}
void solve()
{
    ll n;
    cin>>n;
    if(n%2==1)
    {
        cout<<2<<endl;
    }
    else if(isPowerOfTwo(n)==1)
    {
        cout<<-1<<endl;
    }
    else
    {
        ll ans=2;
        while(n%2==0)
        {
            n=n/2;
            ans=ans*2;
        }
        cout<<min(ans,n)<<endl;
    }

}
int main()
{
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值