https://www.nowcoder.com/acm/contest/112/C
Not too difficult
We can use the recursion to solve it
The code of AC
#include<bits/stdc++.h> using namespace std; typedef unsigned long long ll; ll solve(ll a,ll b){ if(a==b&&a==1) return 1; if(a%2==1) return a/2+1; a/=2; ll c=b/2; if(b%2==1) ++a,++b; return solve(a,b/2)+c; } int main(){ ll n,q; cin>>n>>q; while(q--){ ll b; scanf("%lld",&b); printf("%lld\n",solve(b,n)); } }