from math import gcd P, Q = map(int, input().split()) g = gcd(P, Q) P //= g Q //= g S = set() for i in range(1, int((2*Q)**0.5)+1): if Q % i == 0: S.add(i) S.add(2*Q//i) S = sorted(set(S)) ans = [] for s in S: for t in S: if 2*Q//s+2*Q//t == 2*P: ans.append([s, t]) print(len(ans)) for a in ans: print(*a)