結果

問題 No.2939 Sigma Popcount Problem
ユーザー Carpenters-Cat
提出日時 2024-10-18 22:59:02
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 367 bytes
コンパイル時間 1,899 ms
コンパイル使用メモリ 191,696 KB
最終ジャッジ日時 2025-02-24 21:07:36
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
	ll x;
	cin >> x;
	ll ans = 0;
	int lg = 0;
	while ((x >> lg)) lg ++;
	for (int d = 0; d < lg; d ++) {
		ans += ((x >> (d + 1)) << d);
		ans += max(0ll, (x & ((1ll << (d + 1)) - 1)) - (1ll << d) + 1);
	}
	cout << ans << endl;
}
int main () {
	int N;
	cin >> N;
	while (N--) solve();
}
0