結果
| 問題 | No.3276 Make Smaller Popcount | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-09-19 21:45:15 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 430 ms / 2,000 ms | 
| コード長 | 786 bytes | 
| コンパイル時間 | 1,759 ms | 
| コンパイル使用メモリ | 194,868 KB | 
| 実行使用メモリ | 7,720 KB | 
| 最終ジャッジ日時 | 2025-09-19 21:45:31 | 
| 合計ジャッジ時間 | 15,392 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 28 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pli;
const int N = 2000086, MOD = 1e9 + 7, INF = 0x3f3f3f3f;
ll res;
int n, m, cnt, w[N];
int a[20][20];
int main() {
    int T;
    cin >> T;
    while (T--) {
        cin >> n;
        int c = 0;
        if (__builtin_popcount(n) == 1) {
            puts("-1");
            continue;
        }
        for (int j = 0; j <= 30; j++) {
            if (n >> j & 1) c++;
            else {
                if (c > 1) {
                    ll t = 1 << j;
                    for (int i = j + 1; i <= 30; i++) t += (n >> i & 1) << i;
                    printf("%lld\n", t - n);
                    break;
                }
            }
        }
    }
    return 0;
}
            
            
            
        