def make_divisors(n): lower_divisors , upper_divisors = [], [] i = 1 while i*i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n//i) i += 1 return lower_divisors + upper_divisors[::-1] from math import gcd p,q = map(int,input().split()) g = gcd(p,q) p = p // g q = q // g q2 = q ** 2 nums = make_divisors(q2) ans = [] for num in nums: pn = num + q pm = q2 // num + q if (pn % p == 0) and (pm % p == 0): ans.append([pn // p ,pm // p]) ans.sort() print(len(ans)) for l in ans: print(*l)