#include<bits/stdc++.h>
using namespace std;
#define int long long
int ans=0;
int n,k;
void dfs(int p,int now){
if(p==k||now==0){
ans+=(1+now)*now/2;
return ;
}
int c;
if(now%2==0){
c=now-1;
}
else c=now;
ans+=(1+c)/2*(1+c)/2;
dfs(p+1,now/2);
}
signed main(){
std::ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int T;
cin>>T;
while(T--){
cin>>n>>k;
ans=0;
k=min(32ll,k);
dfs(0,n);
cout<<ans<<endl;
}
return 0;
}
Sum of Numerators (dfs 思维 数论
最新推荐文章于 2022-07-31 13:15:04 发布