#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(a) a.begin(),a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair P; typedef complex com; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; template inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int t; cin >> t; while (t--) { int x, y; cin >> x >> y; int sum = x + y; if (x == y) { int ans = x - 1; if (x % 2 == 0) ans--; vector check; for (int i = 1; i * i <= x; i++) { if (x % i == 0) { check.pb(i); if (i * i != x) check.pb(x / i); } } for (int b : check) { int a = x / b - 1; if (a > 0) ans++; } cout << ans << '\n'; } else { if (x < y) swap(x, y); int ans = 0; vector check; for (int i = 1; i * i <= sum; i++) { if (sum % i == 0) { check.pb(i); if (i * i != sum) check.pb(sum / i); } } for (int i : check) { if (i <= 2) continue; int a = i - 1; if ((x - y) % (a - 1) == 0) { int bpc = (x + y) / (a + 1); int bmc = (x - y) / (a - 1); if ((bpc - bmc) % 2 == 1) continue; int b = (bpc + bmc) / 2; int c = (bpc - bmc) / 2; if (b > 0 && c > 0) ans++; } } cout << ans << '\n'; } } }