#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); long long p, q; cin >> p >> q; long long g = gcd(p, q); p /= g; q /= g; map fac; { long long t = q; for (long long i = 2; i * i <= t; i++) { while (t % i == 0) { fac[i] += 2; t /= i; } } if (t > 1) { fac[t] += 2; } } vector divs; divs.push_back(1); for (auto &i : fac) { int sz = divs.size(); for (int j = 0; j < sz; j++) { long long cur = 1; for (int k = 0; k < i.second; k++) { cur *= i.first; divs.push_back(divs[j] * cur); divs.push_back(-divs[j] * cur); } } } vector> ans; for (long long d : divs) { if (d + q <= 0 || (d + q) % p != 0) { continue; } long long n = (d + q) / p; long long e = q * q / d; if (e + q <= 0 || (e + q) % p != 0) { continue; } long long m = (e + q) / p; ans.push_back({n, m}); } sort(ans.begin(), ans.end()); ans.erase(unique(ans.begin(), ans.end()), ans.end()); cout << ans.size() << "\n"; for (auto [n, m] : ans) { cout << n << " " << m << "\n"; } }