PowerOj 2024-康复赛 (待更新)
PowerOj 2024-康复赛
周六去拔牙了,,,直到中午才拔完牙,这场比赛就缺席了。。。那天晚上伤口还止不住地流血(⊙﹏⊙),那天一晚上都没睡——在床上要不时地起来吐血(⊙﹏⊙)。。。第二天从医院回宿舍睡到下午才起来,想起还有作业要补……
先补思维题吧(⊙﹏⊙)
3408: 暗夜莎露露与超级EZ
对我来说是个纯找规律的题……
分析
代码
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define db(x) cout<<x<<" "<<endl;
#define _db(a,n) for(int i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl;
#define mem(a) memset(a,0, sizeof(a))
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
const int N=1e5+5;
int a[N],b[N];
int fp(int b,int p){
if(p<0) return 0;
int res=1;
while(p){
if(p&1) res*=b;
b=b*b;
p>>=1;
}
return res;
}
void solve(){
int n;cin>>n;
if(n==1){
cout <<1<< endl;
return;
}
int ans=0,tmp=n;
per(i,31,0){
if((n>>i)&1){
ans+=i*fp(2,i-1)+1+tmp-fp(2,i);
tmp-=fp(2,i);
if(tmp==0) break;
}
}
cout <<ans<< endl;
}
signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;cin>>t;while(t--)
solve();
return 0;
}