from math import gcd p, q = map(int, input().split()) pq_gcd = gcd(p, q) p //= pq_gcd q //= pq_gcd PrimeCnt = [] qc = q c = 0 while qc % 2 == 0: c += 1 qc //= 2 if c > 0: PrimeCnt.append((2, 2 * c)) f = 3 while f * f <= qc: c = 0 while qc % f == 0: c += 1 qc //= f if c > 0: PrimeCnt.append((f, 2 * c)) f += 2 if qc != 1: PrimeCnt.append((qc, 2)) Divisors = [1] for pp, c in PrimeCnt: qq = 1 n = len(Divisors) for _ in range(c): qq *= pp for i in range(n): Divisors.append(Divisors[i] * qq) Divisors.sort() ANS = [] for q_ in Divisors: if (q_ + q) % p == 0 and (q * q // q_ + q) % p == 0: ANS.append(((q_ + q) // p, (q * q // q_ + q) // p)) print(len(ANS)) for n, m in ANS: print(n, m)