#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define llint long long #define inf 1e18 #define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++) #define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) using namespace std; typedef pair P; llint T; llint x, y; inline llint calc(llint i) { llint a = i+1, d = (y-x)/i; llint b = (x-d)/(a+1), c = b + d; if(x-d > 0 && (x-d)%(a+1) == 0 && a*c + b == y && a*b + c == x) return 1; return 0; } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> T; for(int t = 0; t < T; t++){ cin >> x >> y; if(x > y) swap(x, y); llint ans = 0; for(int i = 1; i*i <= y-x; i++){ if((y-x)%i) continue; ans += calc(i); if(i*i < y-x) ans += calc((y-x)/i); } cout << ans << endl; } return 0; }