use std::collections::HashSet; fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let s: usize = s.trim().parse().unwrap(); let queries = (0..s).map(|_| { let mut temp = String::new(); std::io::stdin().read_line(&mut temp).ok(); let temp: Vec = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect(); let x = temp[0]; let y = temp[1]; (x.max(y), x.min(y)) }) .collect::>(); for &(x, y) in queries.iter() { let mut factors = HashSet::new(); let mut i = 1; while i*i <= x+y { if (x+y) % i == 0 { if i >= 3 { factors.insert(i); } let val = (x+y) / i; if val >= 3 { factors.insert(val); } } i += 1; } let mut result = 0usize; for &p in factors.iter() { if (x-y) % (p-2) == 0 { let ax = (x+y) / p; let bx = (x-y) / (p-2); if ax > bx && (ax + bx) % 2 == 0{ result += 1; } } } println!("{}", result); } }