#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } vector divs(ll n){ vector ans; for(ll x = 1; x*x <= n; x++){ if(n%x == 0){ ans.push_back(x); if(x*x != n) ans.push_back(n/x); } } sort(ans.begin(), ans.end()); return ans; } using P = pair; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; ll p, q; cin >> p >> q; ll g = gcd(p, q); p /= g; q /= g; auto v = divs(q); vector

ans; for(ll n: v){ for(ll m: v){ if(gcd(n, m) != 1) continue; ll a = q*(n+m), b = n*m; if(a%b != 0) continue; ll px = a/b; if(px%p != 0) continue; ll x = px/p; ans.push_back(P(n*x, m*x)); } } sort(ans.begin(), ans.end()); cout << ans.size() << endl; for(auto [n, m]: ans) cout << n << ' ' << m << endl; }