from math import gcd,ceil,sqrt p,q = map(int,input().split()) g = gcd(p,q) p //= g q //= g if p/q > 2: print(0) elif p//q == 2: print(1) print(1,1) elif p == q + 1: ans = set() ans.add((1,q)) ans.add((q,1)) print(len(ans)) for (n,m) in ans: print(n,m) elif p == q: print(1) print(2,2) elif p/q < 1: nm = [] for n in range(1,ceil(sqrt(q))+1): if (p*n-q > 0) and ((q*n)%(p*n-q) == 0): nm.append((n,(q*n)//(p*n-q))) ans = set() for (n,m) in nm: ans.add((n,m)) ans.add((m,n)) ans = list(ans) ans.sort() print(len(ans)) for (n,m) in ans: print(n,m)