#include #include #include #include #include #include using namespace std; typedef long long int ll; ll X,Y; ll count_res(ll i,ll j){ if(j<2)return 0; ll A=i-1; if(A==1){ if(X!=Y)return 0; else return X-1; } if((A*Y-X)%(A*A-1))return 0; ll C=(A*Y-X)/(A*A-1); if(C<1)return 0; if((X-C)%A)return 0; ll B=(X-C)/A; return B>=1; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int q; cin >> q; while(q--){ cin >> X >> Y; int x=X+Y; ll res=0; for(int i=2;i*i<=x;i++){ if(x%i==0){ res+=count_res(i,x/i); if(x/i!=i&&x/i>=2)res+=count_res(x/i,i); } } cout << res << "\n"; } }