output_description: For each query, print the maximum possible number of participants whose scores
  are smaller than Takahashi's.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      Q
      A_1 B_1
      :
      A_Q B_Q
attempt: #include <iostream>
  using namespace std;
  
  typedef unsigned long long ll;
  
  ll get_upper(ll lower, ll a, ll b) { 
    ll upper = a*b/lower;
    if (upper*lower == a*b) --upper;
    return upper;
  }
  // index が条件を満たすかどうか
  bool isOK(ll lower, ll a, ll b) {
    ll upper = get_upper(lower, a, b);
    return lower <= upper;
  }
  
  int binary_search(ll a, ll b) {
      ll left = a;
      ll right = b-1;
  
      /* どんな二分探索でもここの書き方を変えずにできる！ */
      while (right - left > 1) {
          int mid = left + (right - left) / 2;
  
          if (isOK(mid, a, b)) left = mid;
          else right = mid;
      }
  
      /* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
      return left;
  }
  
  void solve(ll a, ll b)  { 
    if (a > b) swap(a, b);
    ll ans = 2*(a-1); // (a未満, bより大)の数
    ll lower = binary_search(a, b);
    ll upper = get_upper(lower, a, b);
    if (lower < a || upper >= b) {}
    else if (lower == a) { 
      if (lower < upper && upper < b) ++ans;
    }
    else {
      ++ans; // (a, b-1)
      if (lower == upper) ans += (lower-a-1)*2+1;
      else ans += (lower-a)*2;
    }
    // cout << a << " " << b << " " << lower << " " << upper << " " << ans << endl;
    cout << ans << endl;
  }
  
  int main() {
    ll q;
    cin >> q;
    for (ll i = 0; i < q; ++i) {
      ll a, b;
      cin >> a >> b;
      solve(a, b);
    }
  }
  
  
problem_description: Statement
  
  10^{10^{10}} participants, including Takahashi, competed in two programming
  contests. In each contest, all participants had distinct ranks from first
  through 10^{10^{10}}-th.
  
  The _score_ of a participant is the product of his/her ranks in the two
  contests.
  
  Process the following Q queries:
  
    * In the i-th query, you are given two positive integers A_i and B_i. Assuming that Takahashi was ranked A_i-th in the first contest and B_i-th in the second contest, find the maximum possible number of participants whose scores are smaller than Takahashi's.
samples: [{"input": "8\n    1 4\n    10 5\n    3 3\n    4 11\n    8 9\n    22 40\n    8 36\n    314159265 358979323", "output": "1\n    12\n    4\n    11\n    14\n    57\n    31\n    671644785\n    \n\nLet us denote a participant who was ranked x-th in the first contest and y-th\nin the second contest as (x,y).\n\nIn the first query, (2,1) is a possible candidate of a participant whose score\nis smaller than Takahashi's. There are never two or more participants whose\nscores are smaller than Takahashi's, so we should print 1."}]