Advertisement
Guest User

Untitled

a guest
Feb 21st, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. using ll = long long;
  6.  
  7. ll getAt(ll x, ll cl, ll cr, ll pos) {
  8. if (x < 2) {
  9. return x;
  10. }
  11.  
  12. if (cl > cr || cl > pos || cr < pos) {
  13. return 0;
  14. }
  15.  
  16. if (cl == cr) {
  17. return cl == pos ? x : 0;
  18. }
  19.  
  20.  
  21. ll mid = cl + (cr - cl)/2;
  22. if (mid == pos) {
  23. return x&1;
  24. }
  25.  
  26. if (pos < mid) {
  27. return getAt(x/2, cl, mid - 1, pos);
  28. } else {
  29. return getAt(x/2, mid + 1, cr, pos);
  30. }
  31. }
  32.  
  33. int main(int argc, char **argv) {
  34. ios::sync_with_stdio(false);
  35. srand(time(0));
  36.  
  37. ll n, l, r;
  38. cin >> n >> l >> r;
  39. --l, --r;
  40.  
  41. ll ss = pow(2ll, ll(log(n)/log(2)) + 1) - 1;
  42. ll ans = 0ll;
  43. for (ll i = l; i <= r; ++i) {
  44. ans += getAt(n, 0, ss - 1, i);
  45. }
  46. cout << ans << endl;
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement