fn main() { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let p: u64 = itr.next().unwrap().parse().unwrap(); let q: u64 = itr.next().unwrap().parse().unwrap(); let mut v = Vec::new(); let mut n = q; let mut i = 2u64; loop { if i * i > n { break; } if n % i == 0 { v.push(i); while n % i == 0 { n /= i; } } i += 1; } if n > 1 { v.push(n); } let mut n = q * q; let mut d = Vec::new(); d.push(1u64); for x in v.iter() { let l = d.len(); while n % x == 0 { for i in (d.len() - l)..d.len() { let y = d[i] * x; d.push(y); } n /= x; } } let mut ans = Vec::new(); for &d in d.iter() { if (d + q) % p == 0 && (q * q / d + q) % p == 0{ ans.push(((d + q) / p, (q * q / d + q) / p)); } } ans.sort(); ans.dedup(); println!("{}", ans.len()); for a in ans { println!("{} {}", a.0, a.1); } }