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 = 2; while i*i <= x+y { if (x+y) % i == 0 { factors.insert(i); let val = (x+y) / i; factors.insert(val); } i += 1; } let mut result = 0usize; for &p in factors.iter() { if x == y { if p == 1 { continue; } if p == 2 { result += (x+y) / 2 - 1; } else if (x+y) / p % 2 == 0 { result += 1; } continue; } if p >= 3 && (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); } }