結果

問題 No.2939 Sigma Popcount Problem
ユーザー HIcoder
提出日時 2024-12-15 23:28:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 832 bytes
コンパイル時間 1,081 ms
コンパイル使用メモリ 113,508 KB
最終ジャッジ日時 2025-02-26 14:41:14
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<cassert>
#include<random>
#include<set>
#include<map>
#include<cassert>
#include<unordered_map>
#include<bitset>
#include<numeric>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=1<<30;
const ll INF=1LL<<62;
typedef pair<int,ll> P;
typedef pair<int,P> PP; 
const ll MOD=998244353;
const int MAXN=3*1000000;

ll solve(){
    ll N;
    cin>>N;
    N++;
    ll ans=0;
    for(int k=0;k<60;k++){
        ll c=N/(1LL<<(k+1));

        ans+=c*(1LL<<k);
        ll r=N%(1LL<<(k+1));
        r-=(1LL<<k);

        ans+=max(0LL,r);
    }
    return ans;

}

int main(){
    int T;
    cin>>T;
    vector<ll> ans(T);
    for(int t=0;t<T;t++){
        ans[t]=solve();
    }
    for(int t=0;t<T;t++){
        cout<<ans[t]<<endl;
    }
}
0