#![allow(unused_imports)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::io::Write; #[allow(unused_macros)] macro_rules! debug { ($($e:expr),*) => { #[cfg(debug_assertions)] $({ let (e, mut err) = (stringify!($e), std::io::stderr()); writeln!(err, "{} = {:?}", e, $e).unwrap() })* }; } fn get_primes(n: i64) -> Vec { let mut is_prime = vec![true; n as usize + 1]; let mut primes = Vec::new(); is_prime[0] = false; is_prime[1] = false; for i in 2..n + 1 { if is_prime[i as usize] { primes.push(i); let mut j = 2 * i; while j < n { is_prime[j as usize] = false; j += i; } } } primes } fn solve() { let v = read_vec::(); let (x, y) = (max(v[0], v[1]), min(v[0], v[1])); if x == y { solve_eq(x); return; } let mut x_m_y_factors = vec![]; for i in 1.. { if i * i > x - y { break; } if (x - y) % i == 0 { x_m_y_factors.push(i); x_m_y_factors.push((x - y) / i); } } x_m_y_factors.sort(); x_m_y_factors.dedup(); let mut x_p_y_factors = HashSet::new(); for i in 1.. { if i * i > x + y { break; } if (x + y) % i == 0 { x_p_y_factors.insert(i); x_p_y_factors.insert((x + y) / i); } } let mut ans = 0i64; for x_m_y_fact in x_m_y_factors { if !x_p_y_factors.contains(&(x_m_y_fact + 2)) { continue; } let a = x_m_y_fact + 1; let b_m_c = (x - y) / (a - 1); let b_p_c = (x + y) / (a + 1); if (b_m_c + b_p_c) % 2 == 1 { continue; } let b = (b_m_c + b_p_c) / 2; let c = b_p_c - b; if b > 0 && c > 0 { ans += 1; } } println!("{}", ans); } fn solve_eq(x: i64) { // a == 1 let mut ans = x - 1; let mut x_factors = vec![]; for i in 1.. { if i * i > x { break; } if x % i == 0 { x_factors.push(i); x_factors.push(x / i); } } x_factors.sort(); x_factors.dedup(); for fact in x_factors { let b = fact; let a = x / fact - 1; if a > 0 { ans += 1; //debug!(a, b, b); } } println!("{}", ans); } fn main() { let s = read::(); for i in 0..s { solve(); } } fn read() -> T { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim().parse().ok().unwrap() } fn read_vec() -> Vec { read::() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() }