CodeTON Round 1 D

D. K-good

我们考虑变式
我们设我们有一个k
(n-(k+1)k/2)%k=0
n=(k+1)
k/2+kp
2n=k(k+1+2p)
因为我们等式右边 k 和 k+1+2p 奇偶性不同 我们要求的就是k
而对于我们已知的就只有n
我们考虑对n因式分解 分成a*b a表示2的幂 b就表示成一个奇数
这样n也被分成了 奇偶两种不同的 我们分类讨论即可

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
const int M = 998244353;
const int mod = 998244353;
#define int long long
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define pi acos(-1)
#define INF 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);

void solve() {
    int n,m=2;cin>>n;
    while(!(n&1))n>>=1,m<<=1;
    if(n>m)cout<<m<<endl;
    else if(n>1)cout<<n<<endl;
    else cout<<-1<<endl;
}
signed main(){
    fast
    int T;cin>>T;
    while(T--) {
        solve();
    }
    return ~~(0^_^0);
}
posted @ 2022-09-22 15:59  ycllz  阅读(28)  评论(0)    收藏  举报