MAGCARI

Number 1

Feb 18th, 2023
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. /*
  2. 9
  3. 4 1 4
  4. 2 0 2 1 2 0 2
  5. 1 0 1 0 1 0 1 1 1 0 1 0 1 0 1
  6. */
  7. /*
  8. Task : _example
  9. Author : Phumipat C. [MAGCARI]
  10. Language: C++
  11. Created : 19 February 2023 [10:59]
  12. */
  13. #include<bits/stdc++.h>
  14. using namespace std;
  15. int divide(int leftBoundary,int rightBoundary,int number,int leftConsidering,int rightConsidering){
  16. if(rightBoundary < leftConsidering || leftBoundary > rightConsidering) return 0;
  17. if(number <= 1) return number;
  18. int mid = (leftBoundary+rightBoundary-1)/2;
  19. int leftResult = divide(leftBoundary,mid,number/2,leftConsidering,rightConsidering);
  20. int middleResult = number%2;
  21. int rightResult = divide(mid+2,rightBoundary,number/2,leftConsidering,rightConsidering);
  22. return leftResult + middleResult + rightResult;
  23. }
  24. int main(){
  25. int startNumber,l,r;
  26. scanf("%d %d %d",&startNumber,&l,&r);
  27. int n = 1;
  28. while(n < startNumber) n = (2*n) + 1;
  29. printf("%d\n",divide(1,n,startNumber,l,r));
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment