#include #include #include #include using namespace std; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") vector divisor(long long n){//nの約数列挙 vector res; for(long long i = 1; i * i <= n; i++){ if(n % i == 0){ res.push_back(i); if(i != n / i) res.push_back(n / i); } } return res; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int test; cin >> test; for(int counttest = 0; counttest < test; counttest++){ long long X, Y; cin >> X >> Y; long long ans = 0; if(X < Y) swap(X, Y); if(X == Y){ long long t = X + Y; ans += t / 2 - 1; vector d = divisor(t); for(int i = 0; i < (int)d.size(); i++){ if(d[i] > 1 && t / d[i] > 2) ans++; } cout << ans << endl; } else{ long long t1 = X + Y, t2 = X - Y; vector d1 = divisor(t1); for(int i = 0; i < (int)d1.size(); i++){ if(d1[i] > 2){ long long temp = d1[i] - 2; if(t2 % temp == 0 && t1 / d1[i] > t2 / temp && (t1 / d1[i] + t2 / temp) % 2 == 0) ans++; } } cout << ans << endl; } } }