搓逼的第五题做法 #include<cstdio> (5862)#include<cstring> #include<algorithm> (5863)#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; }
点赞 评论

相关推荐

牛客263158796号:我领羊一面后十天不挂也不推进 今天问hr说等前序的第一批意向发完看情况再看是否推进
点赞 评论 收藏
分享
牛客网
牛客企业服务