## https://yukicoder.me/problems/no/2125 import math def calc_gcd(A, B): """ 正の整数A, Bの最大公約数を計算する """ a = max(A, B) b = min(A, B) while a % b > 0: c = a % b a = b b = c return b def main(): P, Q = map(int, input().split()) # P, Qを互いに素な整数として解く gcd = calc_gcd(P, Q) P //= gcd Q //= gcd # Qの約数分解 q_divisors = [] sqrt_q = int(math.sqrt(Q)) for p in range(1, sqrt_q + 1): if Q % p == 0: q = Q // p q_divisors.append(p) if q != p: q_divisors.append(q) answers = [] # nが取りうる値で全探索 q_divisors_set = set(q_divisors) for q in q_divisors: l = Q - q * P r = -Q * q if abs(l) > 0 and abs(r) % abs(l) == 0: if r * l > 0: m = abs(r) // abs(l) if m >= 1: answers.append((q, m)) # 2倍したものも考慮 q *= 2 if q not in q_divisors_set: l = Q - q * P r = -Q * q if abs(l) > 0 and abs(r) % abs(l) == 0: if r * l > 0: m = abs(r) // abs(l) if m >= 1: answers.append((q, m)) print(len(answers)) for n, m in answers: print(n, m) if __name__ == "__main__": main()