p,q = map(int,input().split()) from math import gcd g = gcd(p,q) p //= g q //= g def fact(n): l = [] tmp = n for i in range(2,int(pow(n,0.5))+1): if tmp % i == 0: cnt = 0 while tmp % i == 0: cnt += 1 tmp //= i l.append([i,cnt]) if tmp != 1: l.append([tmp,1]) return l f = fact(q) l = [1] for i,j in f: tmp = l[::1] l = [] for k in range(2*j+1): for now in tmp: l.append(now*pow(i, k)) qq = q*q ans = set() for i in l: j = qq//i i += q j += q if i % p == 0 and j % p == 0: ans.add((i//p, j//p)) ans.add((j//p,i//p)) ans = sorted(list(ans)) print(len(ans)) for i, j in ans: print(i,j)