結果
| 問題 |
No.685 Logical Operations
|
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2018-05-11 23:47:46 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,282 bytes |
| コンパイル時間 | 692 ms |
| コンパイル使用メモリ | 74,340 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-28 09:04:48 |
| 合計ジャッジ時間 | 1,509 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
#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;
}
merom686