require 'prime' class Integer def divisor_list return [] if self <= 0 return [1] if self == 1 prime_division.map.with_index { |(base, k), i| s = i.zero? ? 0 : 1 (s..2 * k).map { |n| base ** n } }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort end end A, B = gets.split.map(&:to_i) gcd = A.gcd(B) P = A / gcd Q = B / gcd ans = [] L = Q ** 2 Q.divisor_list.each do |a| if (a + Q) % P == 0 n = (a + Q) / P b = L / a m = (b + Q) / P ans << [n, m] end end puts ans.size ans.each do |n, m| puts "#{n} #{m}" end