#include "bits/stdc++.h" using namespace std; #define int long long #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i) #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i) #define ALL(a) a.begin(), a.end() #define IN(a, x, b) (a <= x && x < b) templateistream&operator >>(istream&is,vector&vec){for(T&x:vec)is>>x;return is;} templateinline void out(T t){cout << t << "\n";} templateinline void out(T t,Ts... ts){cout << t << " ";out(ts...);} templateinline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;} templateinline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;} constexpr int INF = 1e18; #define endl '\n' #define IOS() ios_base::sync_with_stdio(0);cin.tie(0) void solve(){ //配列は必要な分だけ毎回確保する! int X, Y; cin >> X >> Y; int ans = 0; auto f = [&](int a) -> int { --a; if(1 - a * a == 0) return 0; if ((X - a * Y) % (1 - a * a)) return 0; int c = (X - a * Y) / (1 - a * a); if((X - c) % a) return 0; int b = (X - c) / a; return c > 0 && b > 0; }; for(int i = 2; i * i <= X + Y; ++i) { if((X + Y) % i) continue; ans += f(i); int ni = (X + Y) / i; if(i != ni) ans += f(ni); } out(ans); } signed main(){ IOS(); int Q = 1; cin >> Q; while(Q--)solve(); }