use std::io::Write; fn read_line() -> String { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf } fn read_u() -> usize { let buf = read_line(); buf.trim_end().parse().unwrap() } fn read_i2t() -> (i64, i64) { let buf = read_line(); let mut iter = buf.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap(), ) } fn main () { let stdout = std::io::stdout(); let mut writer = std::io::BufWriter::new(stdout.lock()); let s: usize = read_u(); let get_primes = |n: usize| -> Vec { let mut primes = Vec::new(); let mut is_prime = vec![true; n + 1]; for i in 2..=n { if !is_prime[i] { continue; } primes.push(i as i64); let mut j = i + i; while j <= n { is_prime[j] = false; j += i; } } primes }; let primes = get_primes(100_000); let get_divisors = |mut n: i64| -> Vec { let mut divisors = vec![1]; for &p in &primes { if p * p > n { break; } let len = divisors.len(); let mut q = 1; while n % p == 0 { q *= p; n /= p; for i in 0..len { divisors.push(q * divisors[i]); } } } if n > 1 { let len = divisors.len(); for i in 0..len { divisors.push(n * divisors[i]); } } divisors }; for _ in 0..s { let (x, y): (i64, i64) = read_i2t(); let p = x + y; let q = (x - y).abs(); let mut ans = 0; let divisors = get_divisors(p); for &i in &divisors { if i == 1 { continue; } let j = p / i; if i == 2 { if q > 0 { continue; } ans += j - 1; } else if q % (i - 2) == 0 { let u = j; let v = q / (i - 2); if u > v && (u + v) % 2 == 0 { ans += 1; } } } writeln!(writer, "{}", ans).unwrap(); } }