#include #define rep(i,n) for (int i = 0; i < (n); ++i) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; using P = pair; using VI = vector; using VVI = vector; vector divs(int x) { vector res; for(int i = 1; i * i <= x; ++i) { if (x % i == 0) { res.push_back(i); if (i * i < x) { res.push_back(x / i); } } } return res; } int main() { int tt; cin >> tt; while(tt--) { int x, y; cin >> x >> y; if (x == y) { int ans = x - 1; for(int d: divs(x)) { if (d <= 2) continue; ++ans; } cout << ans << endl; } else { if (x < y) swap(x, y); int p = x + y, q = x - y; int ans = 0; for(int d: divs(q)) { int a = d + 1; if (p % (a + 1) == 0) { int s = p / (a + 1), t = q / (a - 1); ans += s > t && s % 2 == t % 2; } } cout << ans << endl; } } }