MAGCARI

NUmber 1

Feb 20th, 2023
926
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. int l,r;
  5. int cntlen=1,cnt1=0;
  6. void play(ll n,int leftBoundary,int rightBoundary){
  7.     if(rightBoundary < l || leftBoundary > r)   return ;
  8.     if(n == 0 || n == 1){
  9.         if(n == 1)  cnt1++;
  10.         return ;
  11.     }
  12.     int sz = (rightBoundary - leftBoundary) / 2;
  13.     play(n/2,leftBoundary,          leftBoundary + sz - 1);
  14.     play(n%2,leftBoundary + sz,     leftBoundary + sz);
  15.     play(n/2,leftBoundary + sz + 1, rightBoundary);
  16. }
  17. int main(){
  18.     cin.tie(0) -> sync_with_stdio(0);
  19.     ll n;
  20.     cin>>n>>l>>r;
  21.     int cnt = 1;
  22.     int temp = n;
  23.     while(temp > 1) temp/=2,cnt = (2*cnt)+1;
  24.     play(n,1,cnt);
  25.     cout<<cnt1;
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment