#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } int main() { int numCases; for (; ~scanf("%d", &numCases); ) { for (int caseId = 0; caseId < numCases; ++caseId) { Int X, Y; scanf("%lld%lld", &X, &Y); if (X > Y) { swap(X, Y); } Int ans = 0; if (X == Y) { auto check0 = [&](Int d) { if (d > 1) { ++ans; } }; for (Int d = 1; d * d <= X; ++d) { if (X % d == 0) { check0(d); if (d != X / d) { check0(X / d); } } } } else { auto check = [&](Int d) { const Int a = d + 1; const Int denom = a * a - 1; const Int numerB = a * X - Y; const Int numerC = a * Y - X; if (numerB > 0 && numerC > 0 && numerB % denom == 0 && numerC % denom == 0) { ++ans; } }; for (Int d = 1; d * d <= Y - X; ++d) { if ((Y - X) % d == 0) { check(d); if (d != (Y - X) / d) { check((Y - X) / d); } } } } printf("%lld\n", ans); } } return 0; }