結果

問題 No.589 Counting Even
ユーザー @abcde@abcde
提出日時 2019-04-30 09:57:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,139 bytes
コンパイル時間 1,294 ms
コンパイル使用メモリ 143,336 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 21:12:30
合計ジャッジ時間 2,941 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    
    // 1. 入力情報取得.
    LL N;
    cin >> N;
    
    // 2. 1 の 個数 を 計算.
    // Binary Pascal Triangle
    // https://mvtrinh.wordpress.com/2015/02/05/binary-pascal-triangle/
    // -> N を 2進数で表現した場合の 1 の個数 を one と置くと,
    // Binary Pascal Triangle の N段目 の 1の個数 は, 2 の one乗 との内容が記載されている.
    LL one = 0, tN = N;
    do{
        if(tN & 1) one++;
    }while(tN /= 2);
    // cout << "N=" << N << " one=" << one << endl;
    
    // Binary Pascal Triangle の N段目 の 1の個数 を 計算.
    LL bptOne = 1;
    while(one--) bptOne <<= 1;
    // cout << "bptOne=" << bptOne << endl;

    // 3. 出力 ~ 後処理.
    // Binary Pascal Triangle の N段目 の 0の個数 を 計算し, 出力.
    // ex.
    // N = 10 の場合, 10100000101 なので, -> bptZero = 7 のはず.
    // N = 1000000000000000000 の 場合, bptZero = 999999999983222785 で OK ???.
    LL bptZero = (N + 1) - bptOne;
    cout << bptZero << endl;
    return 0;

}
0