#include #define rep(i,n) for (int i = 0; i < (int)(n); i ++) #define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i) using namespace std; using ll = long long; using PL = pair; using P = pair; constexpr int INF = 1000000000; constexpr long long HINF = 1000000000000000; constexpr long long MOD = 1000000007;// = 998244353; constexpr double EPS = 1e-4; constexpr double PI = 3.14159265358979; void solve() { int x,y; cin >> x >> y; int ans = 0; if (x == y) { // A = 1 ans = x - 1; // B = C for (int i = 1;i*i <= x; ++i) { if (x%i == 0) { if (x/i > 1) ++ans; if (i > 1 && x != i*i) ++ans; } } // A = 1 and B = C if (x%2 == 0) { --ans; } cout << ans << '\n'; return ; } if (x < y) swap(x,y); int a = x + y,b = x - y; for (int i = 1;i*i <= b; ++i) { if (b%i == 0) { if (a%(i + 2) == 0 && a/(i + 2) > b/i && a/(i + 2)%2 == b/i%2) ++ans; int c = b/i; if (c == i) continue; if (a%(c + 2) == 0 && a/(c + 2) > i && i%2 == a/(c + 2)%2) ++ans; } } cout << ans << '\n'; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int T; cin >> T; rep(i,T) solve(); return 0; }