結果

問題 No.2939 Sigma Popcount Problem
ユーザー imabcimabc
提出日時 2024-10-19 11:16:19
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 465 bytes
コンパイル時間 5,814 ms
コンパイル使用メモリ 334,380 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-19 11:16:28
合計ジャッジ時間 9,447 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using ld=long double;
using ull=unsigned long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using mint=modint998244353;
const ll INF=1ll<<60;
ll f(ull x){
  if(x==0)return 0;
  else if(x%2)return 2*f((x-1)/2)+(x+1)/2;
  else return f(x-1)+popcount(x);
}
int main(){
  int T; cin>>T;
  while(T--){
    ull N; cin>>N;
    cout<<f(N)<<endl;
  }
}
0