https://codeforces.com/contest/2053/problem/C
#include<bits/stdc++.h>
#define lc p<<1
#define rc p<<1|1
#define INF 2e9
using namespace std;
#define endl '\n'
using ll = long long;
using pii = pair<ll, int>;
const double PI = acos(-1);
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
int k;
ll sum;
pii fun(int l,int r){
ll t=(r-l+1);
if(t>=k){
ll mid=(l+r)>>1;
if(t%2){
auto [sum,cnt]=fun(l,mid-1);
return {sum*2+cnt*mid+mid,2*cnt+1};
}
else {
auto [sum,cnt]=fun(l,mid);
return {sum*2+cnt*mid,2*cnt};
}
}
return {0,0};
}
void solve() {
int n;cin>>n>>k;
cout<<fun(1,n).first<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
cin>>T;
while (T--) {
solve();
}
return 0;
}
标签:cnt,return,递归,int,sum,mid,pair,const
From: https://www.cnblogs.com/laileou/p/18664678