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 num1 = make_divisors(q) num2 = [] for a in num1: for b in num1: num2.append(a * b) ans = [] for num in num2: pn = num + q pm = q**2 // num + q if (pn % p == 0) and (pm % p == 0): ans.append((pn // p ,pm // p)) ans = list(set(ans)) ans.sort() print(len(ans)) for l in ans: print(*l)