結果

問題 No.737 PopCount
ユーザー ats5515ats5515
提出日時 2018-09-28 21:50:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 1,862 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 81,832 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 10:35:29
合計ジャッジ時間 1,984 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
template <typename Int, Int MOD, int N>
struct comb_util {
	std::array<Int, N + 1> fc, ifc;

	comb_util() {
		fc[0] = 1;
		for (int i = 1; i <= N; i++) fc[i] = fc[i - 1] * i % MOD;
		ifc[N] = inv(fc[N]);
		for (int i = N - 1; i >= 0; i--) ifc[i] = ifc[i + 1] * (i + 1) % MOD;
	}

	Int fact(Int n) { return fc[n]; }

	Int inv_fact(Int n) { return ifc[n]; }

	Int inv(Int n) { return pow(n, MOD - 2); }

	Int pow(Int n, Int a) {
		Int res = 1, exp = n;
		for (; a; a /= 2) {
			if (a & 1) res = res * exp % MOD;
			exp = exp * exp % MOD;
		}
		return res;
	}

	Int perm(Int n, Int r) {
		if (r < 0 || n < r)
			return 0;
		else
			return fc[n] * ifc[n - r] % MOD;
	}

	Int binom(Int n, Int r) {
		if (n < 0 || r < 0 || n < r) return 0;
		return fc[n] * ifc[r] % MOD * ifc[n - r] % MOD;
	}

	Int homo(Int n, Int r) {
		if (n < 0 || r < 0) return 0;
		return r == 0 ? 1 : binom(n + r - 1, r);
	}
};

using comb = comb_util<long long, 1000000007, 30000>;
comb cb;
int pc(int N) {
	int res = 0;
	while (N > 0) {
		res += N % 2;
		N /= 2;
	}
	return res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int a = 1;
	int n = N;
	int res = 0;
	for (int i = 0; i < 61; i++) {
		if ((N & a) != 0) {
			n ^= a;
			int p = pc(n);
			for (int j = 0; j <= i; j++) {
				int k;
				if (j == 0) {
					k = 0;
				}
				else {
					k = (((a - 1) % MOD) * cb.binom(i - 1, j - 1)) % MOD;
				}
				res = (res + (((j + p) * k) % MOD)) % MOD;
				res = (res + (((n % MOD)*(j + p) % MOD)*cb.binom(i, j) % MOD)) % MOD;
			}
		}
		a *= 2;
	}
	res = (res + (((N%MOD)*pc(N)) % MOD)) % MOD;
	cout << res << endl;
}
0