fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define pi 3.14159265358979323846264338327950
  4. const int N=1e6+20,mod=(int)(1e9)+7;
  5. #define ull unsigned long long
  6. #define ll long long;
  7. ull solve(ull n,ull k){
  8. //convert to binary
  9. ull sum=0,i=0,z=0;
  10. ull arr[123456];
  11. while(k>0){
  12. int tmp=k%2;
  13. arr[i++]=tmp;
  14. k=k/2;
  15. }
  16. if(i!=n)
  17. {
  18. while(i!=n)
  19. arr[i++]=0;
  20. }
  21. //cout<<i<<endl;
  22. //for(int x=i-1;x>=0;x--)
  23. // cout<<arr[x];
  24. //cout<<endl;
  25. for(int j=i-1;j>=0;j--){
  26. sum=sum+(arr[j]*(ull)pow(2,z++));
  27. }
  28. return sum;
  29. }
  30. int main(){
  31. int t;
  32. cin>>t;
  33. while(t--){
  34. ull n,k;
  35. cin>>n>>k;
  36. printf("%llu\n",solve(n,k));
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0s 16080KB
stdin
1
64 11047805202224836936
stdout
1337369305470044825