結果

問題 No.685 Logical Operations
コンテスト
ユーザー merom686
提出日時 2018-05-11 23:47:46
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,282 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 594 ms
コンパイル使用メモリ 91,100 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-16 21:52:41
合計ジャッジ時間 1,324 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

int main() {
    ll n;
    cin >> n;
    n++;

    ll p[64] = {};
    ll s = 1, t = 1;
    for (int k = 0; k < 61; k++) {
        p[k] = (s - t) % P;
        s *= 4;
        s %= P;
        t *= 3;
        t %= P;
    }

    ll r = 0;
    ll y = 0;
    for (int k = 0; k < 61; k++) {
        ll x = 1LL << k;
        if (x * 2 <= n) {
            r += p[k];
            y = x * 2;
        }
    }
    for (int k = 0; k < 61; k++) {
        ll x = 1LL << k;
        if ((n & x) && x < y) {
            ll s = 1, t = 1;
            for (int i = 0; i < 61; i++) {
                ll z = 1LL << i;
                if (z >= y) break;
                if (z < x) {
                    s *= 4;
                    s %= P;
                    t *= 3;
                    t %= P;
                } else {
                    s *= 2;
                    s %= P;
                    t *= ((n & z) && z > x) ? 1 : 2;
                    t %= P;
                }
            }
            r += s - t;
        }
    }

    r %= P; if (r < 0) r += P;

    cout << r << endl;

    return 0;
}
0