fork download
  1. #pragma GCC optimize("Ofast,unroll-loops")
  2. #pragma GCC target("avx2,tune=native")
  3.  
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6.  
  7. #define ff(i, a, b) for(auto i=(a); i<=(b); ++i)
  8. #define ffr(i, b, a) for(auto i=(b); i>=(a); --i)
  9. #define nl "\n"
  10. #define ss " "
  11. #define mp make_pair
  12. #define pb emplace_back
  13. #define fi first
  14. #define se second
  15. #define sz(s) (int)s.size()
  16. #define all(s) (s).begin(), (s).end()
  17. #define ms(a,x) memset(a, x, sizeof (a))
  18. #define cn continue
  19. #define re exit(0)
  20.  
  21. typedef long long ll;
  22. typedef unsigned long long ull;
  23. typedef long double ld;
  24. typedef vector<int> vi;
  25. typedef vector<ll> vll;
  26. typedef pair<int, int> pii;
  27. typedef pair<ll, ll> pll;
  28. typedef vector<pii> vpii;
  29. typedef vector<pll> vpll;
  30.  
  31. const int mod=1e9+7;
  32. const int mod2=998244353;
  33. const int maxn=1e5+105;
  34. const int maxm=4*maxn+5;
  35. const ll inf=1e16;
  36.  
  37. void rf(){
  38. ios_base::sync_with_stdio(false);
  39. cin.tie(nullptr); cout.tie(nullptr);
  40. if(fopen("o.in","r")){
  41. freopen("o.in","r",stdin);
  42. freopen("o.out","w",stdout);
  43. }
  44. }
  45.  
  46. mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  47. ll ran(ll l, ll r)
  48. {
  49. return uniform_int_distribution<ll> (l, r)(rng);
  50. }
  51.  
  52. template <typename T> void add(T &x, const T &y)
  53. {
  54. x+=y;
  55. if(x>=mod) x-=mod;
  56. if(x<0) x+=mod;
  57. }
  58.  
  59. template <typename T> bool maxi(T &a, T b)
  60. {
  61. if(a>=b) return 0;
  62. a=b; return 1;
  63. }
  64.  
  65. template <typename T> bool mini(T &a, T b)
  66. {
  67. if(a<=b) return 0;
  68. a=b; return 1;
  69. }
  70.  
  71. void solve()
  72. {
  73. ll l, r;
  74. cin >> l >> r;
  75. if (l * 2 <= r) {
  76. cout << r / 2 << nl;
  77. return;
  78. }
  79.  
  80. ll g = r - l;
  81. while (g >= 1) {
  82. ll q_r = r / g;
  83. ll q_l = (l - 1) / g;
  84. if (q_r - q_l >= 2) {
  85. cout << g << nl;
  86. return;
  87. }
  88. g = max(r / (q_r + 1), (l - 1) / (q_l + 1));
  89. }
  90. }
  91.  
  92. signed main()
  93. {
  94. rf();
  95. int t;
  96. if (cin >> t) {
  97. while (t--) {
  98. solve();
  99. }
  100. }
  101. re;
  102. }
Success #stdin #stdout 0s 5320KB
stdin
3
3 5
10 20
100 105
stdout
1
10
5