fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef vector<int> vi;
  5. typedef pair<int,int> pii;
  6. typedef pair<ll,ll> pll;
  7. typedef vector<pii> vpii;
  8. typedef unsigned long long llu;
  9.  
  10. #define debug(x) cerr<<#x<<" "<<x<<endl;
  11. #define f first
  12. //#define s second
  13. #define mp make_pair
  14. #define pb push_back
  15. vi A;
  16. int main()
  17. {
  18. long long n,h,l,zz,k;
  19. long long count=1;
  20. char s='l';
  21. scanf("%d %d",&h,&n);
  22. k=n;
  23. while(k)
  24. {
  25. A.pb(k);
  26. k=k/2;
  27. }
  28. l=A.size();
  29. h++;
  30. for(int i=l-2;i>=0;i--)
  31. { h--;
  32. debug(i);
  33. debug(A[i]);
  34. if(s=='l')
  35. zz=2*A[i+1];
  36. else
  37. zz=2*A[i+1]+1;
  38. if(zz==A[i])
  39. {
  40. if(s=='r')
  41. s='l';
  42. else
  43. s='r';
  44. }
  45. else
  46. count= count+(( (1ll)<<(h))) -1 ;
  47. count++;
  48. }
  49. printf("%d\n",count);
  50. return 0;
  51. }
  52.  
Success #stdin #stdout #stderr 0s 3236KB
stdin
Standard input is empty
stdout
-1791
stderr
i 61
A[i] -2
i 60
A[i] -4
i 59
A[i] -9
i 58
A[i] -18
i 57
A[i] -36
i 56
A[i] -72
i 55
A[i] -145
i 54
A[i] -290
i 53
A[i] -580
i 52
A[i] -1161
i 51
A[i] -2322
i 50
A[i] -4644
i 49
A[i] -9289
i 48
A[i] -18579
i 47
A[i] -37158
i 46
A[i] -74316
i 45
A[i] -148632
i 44
A[i] -297264
i 43
A[i] -594529
i 42
A[i] -1189059
i 41
A[i] -2378119
i 40
A[i] -4756238
i 39
A[i] -9512476
i 38
A[i] -19024952
i 37
A[i] -38049905
i 36
A[i] -76099811
i 35
A[i] -152199622
i 34
A[i] -304399245
i 33
A[i] -608798491
i 32
A[i] -1217596983
i 31
A[i] 1859773330
i 30
A[i] -575420637
i 29
A[i] -1150841274
i 28
A[i] 1993284748
i 27
A[i] -308397801
i 26
A[i] -616795602
i 25
A[i] -1233591204
i 24
A[i] 1827784888
i 23
A[i] -639397521
i 22
A[i] -1278795042
i 21
A[i] 1737377212
i 20
A[i] -820212873
i 19
A[i] -1640425746
i 18
A[i] 1014115804
i 17
A[i] 2028231607
i 16
A[i] -238504082
i 15
A[i] -477008165
i 14
A[i] -954016331
i 13
A[i] -1908032662
i 12
A[i] 478901972
i 11
A[i] 957803944
i 10
A[i] 1915607887
i 9
A[i] -463751522
i 8
A[i] -927503045
i 7
A[i] -1855006091
i 6
A[i] 584955113
i 5
A[i] 1169910226
i 4
A[i] -1955146844
i 3
A[i] 384673608
i 2
A[i] 769347216
i 1
A[i] 1538694432
i 0
A[i] -1217578432