#include #include using namespace std; using ll = long long; vector Divisors(ll N) { ll i = 1; vector u; while (i * i <= N) { if (N % i == 0) { u.push_back(i); if (i * i != N) { u.push_back(N / i); } } i++; } return u; } int main() { ll S, X, Y; ll K, a, p, B, C; vector A; vector u; cin >> S; for (int j = 0; j < S; j++) { cin >> X >> Y; u = Divisors(X + Y); K = 0; for (int i = 0; i < u.size(); i++) { a = u.at(i); if (a == 1) continue; else if (a == 2) { K += (X == Y) * (X - 1); } else { p = a - 1; B = (p * X - Y); C = (-X + p * Y); if (B > 0 && C > 0 && B % (p * p - 1) == 0 && C % (p * p - 1) == 0) { K++; } } } cout << K << endl; } return 0; }