typedef long long ll; typedef long double ld; #include using namespace std; int main() { ll s; std::cin >> s; for (int iii = 0; iii < s; iii++) { ll x,y; std::cin >> x>>y; if(x!=y){ if(y>x)swap(x,y); set yaku; for (int i = 1; i <= sqrt(x-y); i++) { if((x-y)%i==0){ yaku.insert(i); yaku.insert((x-y)/i); } } ll ans = 0; for (auto e : yaku) { ll a = e+1; if((x+y)%(a+1)!=0)continue; if( ( (x+y)/(a+1)+(x-y)/(a-1) )%2!=0) continue; if( ( (x+y)/(a+1)-(x-y)/(a-1) )%2!=0) continue; if( ( (x+y)/(a+1)-(x-y)/(a-1))/2 <= 0 ) continue; if( x == a*( (x+y)/(a+1)+(x-y)/(a-1) )/2+( (x+y)/(a+1)-(x-y)/(a-1))/2 )ans++; } std::cout << ans << std::endl; }else{ set yaku; for (int i = 1; i <= sqrt(x); i++) { if(x%i==0){ yaku.insert(i); yaku.insert(x/i); } } std::cout << x-2+yaku.size() << std::endl; } } }