搓逼的第五题做法
#include<cstdio> #include<cstring>
#include<algorithm> #include<iostream> #include<cmath> using namespace std; typedef long long ll; const int maxn = 100000 + 5; ll a[maxn]; int main(){ //cout<<log2(100000000000000000)<<endl; int t,k; ll x; scanf("%d",&t); while(t--){ scanf("%lld%d",&x,&k); int cnt = log2(x); if(k > cnt){ printf("-1\n"); } else{ int t = 0; while(x > (ll)0){ if(x % (ll)2 == 0){ //cout<<x / (ll)2<<endl; a[t ++] = x / (ll)2; //cout<<a[t - 1]<<endl; x /= (ll)2; } else{ a[t ++] = (x - (ll)1) / (ll)2; x = (x - (ll)1) / (ll)2; } } printf("%lld\n",a[t - k - 1]); } } return 0; }