#include using namespace std; using ll = long long; void calc_ft(const vector>& x, int id, ll y, vector& ret) { if (id == x.size()) { ret.push_back(y); return; } auto [f, c] = x[id]; ll pk = 1; for (int i = 0; i <= c; i ++) { calc_ft(x, id + 1, y * pk, ret); pk *= f; } } int main () { ll P, Q; cin >> P >> Q; ll Q2 = Q * Q; vector> fts; ll q = Q; for (ll x = 2; x * x <= Q; x ++) { if (Q % x) { continue; } int c = 0; while (Q2 % x == 0) { Q2 /= x; c ++; } while (q % x == 0) { q /= x; } fts.emplace_back(x, c); } if (q > 1) { fts.emplace_back(q, 2); } vector R; calc_ft(fts, 0, 1, R); sort(R.begin(), R.end()); vector> ans; Q2 = Q * Q; for (auto d : R) { ll d2 = Q2 / d; if (((d + Q) % P) ||((d2 + Q) % P)) { continue; } ans.emplace_back((d + Q) / P, (d2 + Q) / P); } cout << ans.size() << endl; for (auto [n, m] : ans) { cout << n << " " << m << endl; } }