import math p, q = map(int, input().split()) g = math.gcd(p, q) p //= g q //= g q_divs = [] for x in range(1, int(math.sqrt(q)) + 1): if q % x == 0: q_divs.append(x) if x != q // x: q_divs.append(q // x) divs = set() for i in range(len(q_divs)): for j in range(i, len(q_divs)): divs.add(q_divs[i] * q_divs[j]) ans = [] for x in divs: y = (q * q) // x if (x + q) % p != 0 or (y + q) % p != 0: continue m = (x + q) // p n = (y + q) // p if m > 0 and n > 0: ans.append((m, n)) ans.sort() print(len(ans)) for m, n in ans: print(f"{m} {n}")