fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4.  
  5. bool cmd(pair<ll, ll> a, pair<ll, ll> b) {
  6. if (a.first != b.first)
  7. return a.first < b.first;
  8. return a.second > b.second;
  9. }
  10. int main() {
  11. ios::sync_with_stdio(0);
  12. cin.tie(NULL), cout.tie(NULL);
  13. //freopen("mex.in", "r", stdin);
  14.  
  15. ll t = 1;cin >> t;
  16. while (t--) {
  17. ll l, r,div=3,count=1,ans=0;
  18. cin >> l >> r;
  19. while (l >= div) {
  20. div *= 3;
  21. count++;
  22. }
  23. ans += count;
  24. for (ll i = l; i <= r; i++) {
  25. if (i >= div) {
  26. div *= 3;
  27. count++;
  28. }
  29. ans += count;
  30. //cout << count << "\n";
  31. }
  32. cout << ans << '\n';
  33. }
  34. return 0;
  35. }
  36. /*a
  37. 3 3
  38. 5 3 2
  39. 1 2
  40. 2 3
  41. 1 3
  42. 8
  43. 8
  44. 10
  45.  
  46. */
Success #stdin #stdout 0.01s 5276KB
stdin
4
1 3
2 4
199999 200000
19 84
stdout
5
6
36
263