#include #include using namespace std; using ll = long long; using namespace boost::multiprecision; ll solve (int A, int B) { auto f = [&](ll X) -> bool { cpp_int a = A, b = B, x = X; return 0 < x*x - a - b && 4 * a * b < (x*x - (a+b)) * (x*x - (a+b)); }; ll ok = 65000, ng = 0; while (1 < abs(ok-ng)) { ll mid = (ok + ng) / 2; if (f(mid)) { ok = mid; } else { ng = mid; } } return ok; } int main () { int N; cin >> N; // 二回2乗してやれば二分探索できそうな形になる(った) // -> アッ、二乗したときに符号関連の情報が死んでるっぽい while (N--) { int A, B; cin >> A >> B; auto ans = solve(A, B); cout << ans << "\n"; } }