CF1656 D. K-good (构造) (未评分)

https://codeforces.com/contest/1656/problem/D

  • 明显奇数直接rangk等于2
  • 偶数:
    image
    image
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false) ,cin.tie(0), cout.tie(0);
//#pragma GCC optimize(3,"Ofast","inline")
typedef long long ll;
const int N = 1e5 + 5;
const int M = 1e6 + 5;
const ll LNF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;

void solve() {
    ll n; cin >> n;
    if(n & 1) {
         cout << 2 << endl;
    } else {
        ll t = 1;
        while (n % 2 == 0){
            n /= 2; t *= 2;
        }
        if(n == 1) {
            cout << -1 << endl;
        }
        if(n != 1) {
            cout << min(n, t * 2) << endl;
        }
    }
}
int main () {
    int t; cin >> t;
    while(t --) solve();
    return 0;
}
posted @ 2022-03-25 10:46  qingyanng  阅读(31)  评论(0编辑  收藏  举报