Submission #466178

# Submission time Handle Problem Language Result Execution time Memory
466178 2021-08-18T10:15:07 Z sinamhdv Party (INOI20_party) C++11
0 / 100
98 ms 376 KB
#include <bits/stdc++.h>
using namespace std;

#define int ll

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const ll LINF = 1e18 + 100;

#ifdef DEBUG
#define dbg(x) cout << #x << " = " << (x) << endl << flush;
#define dbgr(s, f) { cout << #s << ": "; for (auto _ = (s); _ != (f); _++) cout << *_ << ' '; cout << endl << flush; }
#else
#define dbg(x) ;
#define dbgr(s, f) ;
#endif
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define fr first
#define sc second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

const int LOGN = 62;

int q;
ll n;
int k;
ll outdp[LOGN][LOGN];
ll dp[LOGN][LOGN];
ll ans;

ll poww(ll a, ll b)
{
	a %= mod, b %= mod;
	ll res = 1;
	while (b)
	{
		if (b & 1) res = res * a % mod;
		a = a * a % mod;
		b /= 2;
	}
	return res;
}

inline void tcase(void)
{
	memset(dp, 0, sizeof(dp));
	memset(outdp, 0, sizeof(outdp));
	ans = 0;

	cin >> n;
	k = __builtin_popcountll(n);

	FOR(i, 1, k)
	{
		FOR(x, 1, LOGN)
		{
			outdp[i][x] = outdp[i - 1][x - 1] + (x >= 2 && i + x - 2 < k ? (1ll << (x - 2)) : 0) + (x == 1);
		}
		dbg(i);
		dbgr(outdp[i], outdp[i] + 10);
	}

	dbg("========================\n\n");

	FOR(i, 0, k)
	{
		dp[i][LOGN - 1] = outdp[i][LOGN - 1];
		for (int x = LOGN - 2; x >= 0; x--) dp[i][x] = dp[i][x + 1] + outdp[i][x] + (i + x < k ? (1ll << x) : 0);

		dbg(i);
		dbgr(dp[i], dp[i] + 10);
	}

	FOR(i, 0, k)
	{
		ll val = 0;
		FOR(x, 1, LOGN - 1) val += (ll)x * (poww(2, dp[i][x]) - poww(2, dp[i][x + 1])) % mod;
		ans = (ans + val * ((1ll << i) % mod) % mod) % mod;
	}

	dbg(ans);

	ans = ans * poww((poww(2, n) - 1) % mod, mod - 2) % mod;
	ans = (mod + ans % mod) % mod;
	cout << ans << endl;
}

int32_t main(void)
{
	fast_io;

	cin >> q;
	while (q--) tcase();

	return 0;
}

# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 98 ms 356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -