use std::io::{BufRead, Write}; fn main () { let stdin = std::io::stdin(); let stdout = std::io::stdout(); let mut reader = std::io::BufReader::new(stdin.lock()); let mut writer = std::io::BufWriter::new(stdout.lock()); let s: usize = { let mut buf = String::new(); reader.read_line(&mut buf).unwrap(); buf.trim_end().parse().unwrap() }; for _ in 0..s { let (x, y): (i64, i64) = { let mut buf = String::new(); reader.read_line(&mut buf).unwrap(); let mut iter = buf.split_whitespace(); ( iter.next().unwrap().parse().unwrap(), iter.next().unwrap().parse().unwrap(), ) }; let z = x + y; let mut ans = 0; let mut i = 2; while i * i <= z { if z % i == 0 { { let a = i - 1; let q = z / i; if a > 1 && (x - q) % (a - 1) == 0 && (y - q) % (a - 1) == 0 { let b = (x - q) % (a - 1); let c = (y - q) % (a - 1); if b + c == q { ans += 1; } } } if i * i != z { let a = z / i - 1; let q = i; if a > 1 && (x - q) % (a - 1) == 0 && (y - q) % (a - 1) == 0 { let b = (x - q) % (a - 1); let c = (y - q) % (a - 1); if b + c == q { ans += 1; } } } } i += 1; } writeln!(writer, "{}", ans).unwrap(); } }