結果

問題 No.737 PopCount
ユーザー potoooooooopotoooooooo
提出日時 2018-09-28 23:58:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,065 bytes
コンパイル時間 1,584 ms
コンパイル使用メモリ 165,124 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 12:15:52
合計ジャッジ時間 2,334 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007

long long modpow(int n, int r) {
  long long ret = 1; long long tmp = (long long) n;
  while (r != 0) {
    if (r % 2) ret *= tmp;
    tmp *= tmp; tmp %= mod; ret %= mod;
    r /= 2;
  }
  return ret;
}

int main(){
  long long n; cin >> n;
  long long ans = 0; long long k = 0;
  long long inv2 = modpow(2, mod-2);
  long long c = n;
  while (c > 0) k++, c /= 2;
  for (int digit = 0; digit < k; digit++) {
    int di = digit + 1;
    if (n & (1 << digit)) {
      long long han = (n >> digit) << digit;
      long long tmp = ((n+han)%mod) * ((n-han+1)%mod);
      ans += ((tmp%mod)*inv2) % mod; ans %= mod;
    }
    long long u = (n >> di); long long v = (1 << digit);
    long long ini = (((v%mod)*((v-1)%mod))%mod)*inv2%mod;
    long long diff = (v*2%mod) * (v%mod) % mod;
    ans += (u % mod) * (((v%mod) * (v%mod)) % mod);
    ans %= mod;
    ans += (ini * u) % mod; ans %= mod;
    ans += (((((diff%mod)*(u%mod)%mod)*((u-1)%mod))%mod)*inv2)%mod;
  }
  cout << ans << endl;
  return 0;
}
0