結果
| 問題 | No.680 作れる数 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-04-27 22:43:55 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 2,000 ms | 
| コード長 | 492 bytes | 
| コンパイル時間 | 1,513 ms | 
| コンパイル使用メモリ | 167,872 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-27 22:02:10 | 
| 合計ジャッジ時間 | 2,418 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 20 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll calc(int x) {
    ll res = 0;
    while (x > 0) {
        res += x;
        x >>= 1;
    }
    return res;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ok = 0, ng = n + 1;
    while (ng - ok > 1) {
        int mid = (ok + ng) / 2;
        if (calc(mid) <= n) ok = mid;
        else ng = mid;
    }
    cout << (calc(ok) == n ? "YES" : "NO") << endl;
    return 0;
}
            
            
            
        