#include #include #include #include #include #include #include using namespace std; typedef long long ll; void solve(){ int x, y; cin >> x >> y; if(x < y) swap(x, y); if(x == y){ int ans = 0; // a = 1 ans += x-1; // b = c for(int i = 1; i*i <= x; i++){ if(x%i == 0) { if(i != 1)ans++; if(i*i != x) ans++; } } if(x%2 == 0) ans--; cout << ans << endl; return; } int ans = 0; for(int s = 1; s*s <= x-y; s++){ if((x-y)%s != 0) continue; { int t_ = (x-y)/s; int a = s+1; if((x+y)%(a+1) == 0){ int t = (x+y)/(a+1); if(t > t_ && t%2 == t_%2) { ans++; } } } if(s*s != x-y){ int t_ = s; int a = (x-y)/t_+1; if((x+y)%(a+1) == 0){ int t = (x+y)/(a+1); if(t > t_ && t%2 == t_%2) { ans++; } } } } cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int s; cin >> s; for(int i = 0; i < s; i++) solve(); }