Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- using ll = long long;
- int l,r;
- int cntlen=1,cnt1=0;
- void play(ll n,int leftBoundary,int rightBoundary){
- if(rightBoundary < l || leftBoundary > r) return ;
- if(n == 0 || n == 1){
- if(n == 1) cnt1++;
- return ;
- }
- int sz = (rightBoundary - leftBoundary) / 2;
- play(n/2,leftBoundary, leftBoundary + sz - 1);
- play(n%2,leftBoundary + sz, leftBoundary + sz);
- play(n/2,leftBoundary + sz + 1, rightBoundary);
- }
- int main(){
- cin.tie(0) -> sync_with_stdio(0);
- ll n;
- cin>>n>>l>>r;
- int cnt = 1;
- int temp = n;
- while(temp > 1) temp/=2,cnt = (2*cnt)+1;
- play(n,1,cnt);
- cout<<cnt1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment