搓逼的第五题做法 #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; }
点赞 评论

相关推荐

今天 11:10
武汉纺织大学 C++
点赞 评论 收藏
分享
02-17 20:43
西北大学 Java
醉蟀:别浪费时间。老板是一个想入行互联网的新人。去年6 7月boss上面看到的。他把所有人都拉到一个微信群,然后一个一个面,自己也在学技术。公司就是一个小区里面租的两间房。都没有买电脑啥的。
点赞 评论 收藏
分享
牛客网
牛客企业服务