#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; ll powmod(__int128_t a, ll k, ll m){ __int128_t ap=a, ans=1; while(k){ if(k&1){ ans*=ap; ans%=m; } k>>=1; ap=ap*ap%m; } return ans; } bool is_prime(ll n){ if(n<=1 || !(n&1)) return (n==2); ll d=n-1; int k=0; while(!(d&1)){ d>>=1; k++; } vector va{2, 325, 9375, 28178, 450775, 9780504, 1795265022}; // http://miller-rabin.appspot.com/ for(auto aa:va){ ll a=aa%n; if(a==0) continue; bool comp=1; ll ap=powmod(a, d, n); if(ap==1 || ap==n-1) continue; for(int r=1; r>=__builtin_ctzll(a); while(b){ b>>=__builtin_ctzll(b); if(a>b) swap(a, b); b-=a; } return a<> factorize(ll n){ if(n<=1){ vector> ret; return ret; } map mp; vector v(1, n); ll c=1; while(!v.empty()){ ll x=v.back(); v.pop_back(); if(is_prime(x)){ mp[x]++; continue; } ll p=rho(x, c); v.push_back(p); v.push_back(x/p); } vector> ret; for(auto p:mp) ret.push_back(p); return ret; } ll calc(ll a, ll s, ll x, ll y){ if(a==0) return 0; if(a==1){ if(x==y) return s-1; else return 0; } if(x<=s) return 0; if((x-s)%(a-1)==0 && (x-s)/(a-1) &v, ll &ans){ if(k==v.size()){ ans+=calc(d-1, (x+y)/d, x, y); return; } ll q=1; for(int i=0; i<=v[k].second; i++){ dfs(k+1, d*q, x, y, v, ans); q*=v[k].first; } } ll solve(ll x, ll y){ ll ans=0; auto v=factorize(x+y); dfs(0, 1, x, y, v, ans); return ans; } int main() { int s; cin>>s; while(s--){ ll x, y; cin>>x>>y; cout<