/* -*- coding: utf-8 -*- * * 2420.cc: No.2420 Simple Problem - yukicoder */ #include #include using namespace std; /* constant */ /* typedef */ typedef long long ll; /* global variables */ /* subroutines */ /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { int a, b; scanf("%d%d", &a, &b); // sqrt(a)+sqrt(b) (sqrt(a)+sqrt(b))^2=a+b+2sqrt(a)sqrt(b) 2sqrt(a)sqrt(b) 4ab<(x^2-(a+b))^2 ll d = 4LL * a * b; ll e0 = 0, e1 = 2000000001; while (e0 + 1 < e1) { ll e = (e0 + e1) / 2; if (e * e > d) e1 = e; else e0 = e; } //printf("e1=%lld\n", e1); ll f = e1 + (a + b); ll x0 = 0, x1 = 4000000001LL; while (x0 + 1 < x1) { ll x = (x0 + x1) / 2; if (x * x >= f) x1 = x; else x0 = x; } printf("%lld\n", x1); } return 0; }