fork download
  1. #include <iostream>
  2. #define LL long long
  3. using namespace std;
  4. LL rez=0;
  5. LL lg2(LL nr)
  6. {
  7. LL x=-1;
  8. while(nr)
  9. {
  10. nr>>=1;
  11. x++;
  12. }
  13. return x;
  14. }
  15. LL sizeofnr(LL nr)
  16. {
  17. return (1LL<<(lg2(nr)+1))-1;
  18. }
  19. void q(LL nr,LL l,LL r)
  20. {
  21. LL len=sizeofnr(nr),halflen=len/2;
  22. if(len<=1){rez+=nr;return ;}
  23. if(l<=halflen)
  24. q(nr/2,l,min(halflen,r));
  25. if(l<=halflen+1&&r>=halflen+1)
  26. q(nr%2,halflen+1,halflen+1);
  27. if(r>halflen+1)
  28. q(nr/2,max(halflen+2,l)-halflen-1,r-halflen-1);
  29. }
  30. int main()
  31. {
  32. LL N,l,r;
  33. cin>>N>>l>>r;
  34. q(N,l,r);
  35. cout<<rez;
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
Standard output is empty