#include "iostream" #include "vector" 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; long long ans = 0; auto f = [&](int a) -> int { --a; if ((X - a * Y) % (1 - a * a)) return 0; int c = (X - a * Y) / (1 - a * a); if((X - c) % a) return 0; return c > 0 && X - c > 0; }; int loop = min(X + Y, max(X, Y) + (int)2e8); for(int i = 3; i * i <= loop; ++i) { if((X + Y) % i) continue; ans += f(i); int ni = (X + Y) / i; if(i != ni) ans += f(ni); } if((X + Y) % 2 == 0) ans += f((X + Y) / 2); out(ans); } signed main(){ IOS(); int Q = 1; cin >> Q; while(Q--)solve(); }