結果
| 問題 | No.3276 Make Smaller Popcount | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-09-19 22:04:52 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 437 ms / 2,000 ms | 
| コード長 | 697 bytes | 
| コンパイル時間 | 2,898 ms | 
| コンパイル使用メモリ | 275,728 KB | 
| 実行使用メモリ | 7,716 KB | 
| 最終ジャッジ日時 | 2025-09-19 22:05:10 | 
| 合計ジャッジ時間 | 17,023 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 28 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const ll INF = 1e18;
void solve() {
    int n;
    cin >> n;
    
    int pc = __builtin_popcount(n);
    if (pc == 1) {
        puts("-1");
        return;
    }
    
    ll ans = INF;
    for (int k = 1; k <= 31; ++k) {
        ll mod = n&((1ll<<k)-1);
        ll x = (1ll<<k) - mod;
        if (x == 0) continue;
        ll y = n+x;
        if (__builtin_popcountll(y) < pc) {
            ans = min(ans, x);
        }
    }
    
    if (ans == INF) ans = -1;
    cout << ans << '\n';
}
int main() {
    int t;
    cin >> t;
    
    while (t--) solve();
    
    return 0;
}
            
            
            
        