--[[ (x + y) / xy = p / q xyp = (x + y)q y = xq / (xp - q) ]] p, q = io.read("*n", "*n") local t = {} for x = 1, 32000 do local a = x * q local b = x * p - q if 0 < b and a % b == 0 then local y = math.floor(a / b) if x < y then table.insert(t, {x, y}) table.insert(t, {y, x}) elseif x == y then table.insert(t, {x, x}) end end end table.sort(t, function(a, b) return a[1] < b[1] end) print(#t) for i = 1, #t do print(t[i][1] .. " " .. t[i][2]) end