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() -> (i32, i32) { 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_divisors = |n: i32| -> Vec { let mut divisors = vec![]; for p in 1.. { if p * p > n { break; } if n % p > 0 { continue; } divisors.push(p); if p * p == n { continue; } divisors.push(n / p); } divisors }; for _ in 0..s { let (x, y): (i32, i32) = 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(); } }