結果
| 問題 |
No.2939 Sigma Popcount Problem
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2024-10-18 21:35:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 2,000 ms |
| コード長 | 1,821 bytes |
| コンパイル時間 | 681 ms |
| コンパイル使用メモリ | 74,020 KB |
| 最終ジャッジ日時 | 2025-02-24 20:32:11 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
const i64 INF = 1001001001001001001;
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
#include <atcoder/modint>
namespace nachia{
int Popcount(unsigned long long c) noexcept {
#ifdef __GNUC__
return __builtin_popcountll(c);
#else
c = (c & (~0ull/3)) + ((c >> 1) & (~0ull/3));
c = (c & (~0ull/5)) + ((c >> 2) & (~0ull/5));
c = (c & (~0ull/17)) + ((c >> 4) & (~0ull/17));
c = (c * (~0ull/257)) >> 56;
return c;
#endif
}
// please ensure x != 0
int MsbIndex(unsigned long long x) noexcept {
#ifdef __GNUC__
return 63 - __builtin_clzll(x);
#else
using u64 = unsigned long long;
int q = (x >> 32) ? 32 : 0;
auto m = x >> q;
constexpr u64 hi = 0x8888'8888;
constexpr u64 mi = 0x1111'1111;
m = (((m | ~(hi - (m & ~hi))) & hi) * mi) >> 35;
m = (((m | ~(hi - (x & ~hi))) & hi) * mi) >> 31;
q += (m & 0xf) << 2;
q += 0x3333'3333'2222'1100 >> (((x >> q) & 0xf) << 2) & 0xf;
return q;
#endif
}
// please ensure x != 0
int LsbIndex(unsigned long long x) noexcept {
#ifdef __GNUC__
return __builtin_ctzll(x);
#else
return MsbIndex(x & -x);
#endif
}
}
using Modint = atcoder::static_modint<998244353>;
using namespace std;
void testcase(){
i64 N; cin >> N; N += 1;
i64 ans = 0;
i64 m = 1;
while(N){
if(N % 2 == 1) ans += nachia::Popcount(N-1) * m;
N /= 2;
ans += N * m;
m *= 2;
}
cout << ans << '\n';
}
int main(){
ios::sync_with_stdio(false); cin.tie(nullptr);
i64 T; cin >> T;
rep(t,T) testcase();
return 0;
}
Nachia