結果
| 問題 | No.737 PopCount |
| コンテスト | |
| ユーザー |
startcpp
|
| 提出日時 | 2018-12-29 18:23:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 915 bytes |
| 記録 | |
| コンパイル時間 | 434 ms |
| コンパイル使用メモリ | 56,196 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-01 20:38:23 |
| 合計ジャッジ時間 | 1,274 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 |
ソースコード
#include <iostream>
#define int long long
using namespace std;
int mod = 1000000007;
int inv2 = 500000004;
int g[60]; //popcount(0)~popcount(2^n - 1)の和
int f[60]; //V(0)~V(2^n - 1)の和。ただしV(i) = i * popcount(i)
//l + … + r - 1
int wa(int l, int r) {
int n = r - l;
n %= mod;
l %= mod;
return (n * (n - 1) % mod * inv2 + l * n % mod) % mod;
}
signed main() {
int i;
g[0] = 0;
for (i = 1; i < 60; i++) {
g[i] = 2 * g[i - 1] + (1LL << (i - 1)) % mod;
g[i] %= mod;
}
f[0] = 0;
for (i = 1; i < 60; i++) {
f[i] = 2 * f[i - 1] + (1LL << (i - 1)) % mod * g[i - 1] + wa(1LL << (i - 1), 1LL << i);
f[i] %= mod;
}
int n;
cin >> n;
n++;
int l = 0, cnt = 0;
int ans = 0;
for (i = 59; i >= 0; i--) {
if ((n >> i) & 1) {
ans += f[i] + l % mod * g[i] + cnt * wa(l, l + (1LL << i));
ans %= mod;
cnt++;
l += (1LL << i);
}
}
cout << ans << endl;
return 0;
}
startcpp