#include #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define rrep(i, n) for (int i = (int)n-1; i >= 0; --i) using namespace std; using ll = long long; template inline bool chmax(T& a, const T& b) { if (a < b){ a = b; return true; } return false; } template inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } return false; } /** * @brief 多次元 vector の作成 * @author えびちゃん */ namespace detail { template auto make_vec(vector& sizes, T const& x) { if constexpr (N == 1) { return vector(sizes[0], x); } else { int size = sizes[N-1]; sizes.pop_back(); return vector(size, make_vec(sizes, x)); } } } template auto make_vec(int const(&sizes)[N], T const& x = T()) { vector s(N); for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1]; return detail::make_vec(s, x); } __attribute__((constructor)) void fast_io() { ios::sync_with_stdio(false); cin.tie(nullptr); } vector enum_div(long long n) { vector res; for (long long i = 1; i*i <= n; i++) { if (n%i) continue; res.push_back(i); if (i*i != n) res.push_back(n/i); } sort(res.begin(), res.end()); return res; } void solve() { int x, y; cin >> x >> y; if (x > y) swap(x, y); int sum = x + y; int diff = y - x; auto sum_div = enum_div(sum); auto diff_div = enum_div(diff); int n = sum_div.size(), m = diff_div.size(); int idx = 0; int cnt = 0; rep(i, n-1) { while (idx < m && diff_div[idx] < sum_div[i] - 2) idx++; if (idx == m) break; if (diff_div[idx] == sum_div[i] - 2) { int p = sum / sum_div[i], q = diff / diff_div[idx]; if (p % 2 != q % 2 or p - q < 0) continue; int b = (p + q) / 2, c = (p - q) / 2; if (b <= x && c <= x) cnt++; } } cout << cnt << '\n'; } int main() { int t; cin >> t; while (t--) solve(); }