Created
February 20, 2017 18:58
-
-
Save Acarus/30fe208fc45ce6c280c7d1dd2654f904 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
using ll = long long; | |
ll getAt(ll x, ll cl, ll cr, ll pos) { | |
if (cl == cr && cl == pos) { | |
return x; | |
} | |
ll mid = cl + (cr - cl)/2; | |
if (mid == pos) { | |
return x&1; | |
} | |
if (pos < mid) { | |
return getAt(x/2, cl, mid - 1, pos); | |
} else { | |
return getAt(x/2, mid + 1, cr, pos); | |
} | |
} | |
int main(int argc, char **argv) { | |
// ios::sync_with_stdio(false); | |
srand(time(0)); | |
#ifndef ONLINE_JUDGE | |
freopen("/home/acarus/input.txt", "r", stdin); | |
#endif | |
ll n, l, r; | |
scanf("%lld %lld %lld", &n, &l, &r); | |
--l, --r; | |
ll s = log(n)/log(2); | |
ll ss = 1ll; | |
for (int i = 0; i < s; ++i) { | |
ss = ss * 2 + 1; | |
} | |
ll cl = 0, cr = ss - 1; | |
ll ans = 0ll; | |
for (ll i = l; i <= r; ++i) { | |
ans += getAt(n, cl, cr, i); | |
} | |
printf("%lld\n", ans); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment