fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. long long count(long long x, int i) {
  5. long long step = 1ll << (i+1);
  6. long long from = 1ll << i;
  7. if (x < from) return 0;
  8. long long res = (x - from) / step + 1;
  9. return res;
  10. }
  11.  
  12. int main() {
  13. long long L, R;
  14. cin >> L >> R;
  15. long long ans = 0;
  16. for(int i=1; (1ll <<i)<=R; i++) {
  17. long long cntR = count(R, i);
  18. long long cntL = count(L-1, i);
  19. ans += (cntR - cntL) * i;
  20. }
  21. cout << ans;
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 5320KB
stdin
7
stdout
140734196944063