結果

問題 No.3276 Make Smaller Popcount
ユーザー Jikky1618
提出日時 2025-09-20 01:18:33
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 886 bytes
コンパイル時間 3,011 ms
コンパイル使用メモリ 275,816 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-20 01:18:40
合計ジャッジ時間 7,051 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 25 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...)
#endif

void solve() {
    int N;
    cin >> N;
    // popcount(N) = 1 の場合, No
    if (__builtin_popcount(N) == 1) {
        cout << "No" << "\n";
        return;
    }
    // 右から 2 個目の 1 の位置を求める
    int ctz = __builtin_ctz(N);
    for (int i = ctz + 1; i < 30; i++) {
        if (N & (1 << i)) {
            ctz = i;
            break;
        }
    }
    debug(N, ctz);
    // 右から [0, ctz] 桁目は 0 に, ctz + 1 桁目を 1 を加算
    int M = N;
    for (int i = 0; i <= ctz; i++) M &= ~(1 << i);
    M += (1 << (ctz + 1));
    cout << M - N << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int T;
    cin >> T;
    while (T--) solve();
}
0