結果
問題 | No.589 Counting Even |
ユーザー |
![]() |
提出日時 | 2019-04-30 09:57:13 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,139 bytes |
コンパイル時間 | 1,505 ms |
コンパイル使用メモリ | 157,840 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-28 04:46:13 |
合計ジャッジ時間 | 2,562 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 29 |
ソースコード
#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; }