#include using namespace std; #define ll long long #define all(x) x.begin(),x.end() #define rep(i,a,b) for(int i=a;i<=b;i++) #define rep_r(i,a,b) for(int i=a;i>=b;i--) #define each(a,x) for (auto& x : a) using pi = pair; using pl = pair; using vi = vector; using vl = vector; #define sz(x) int(x.size()) #define so(x) sort(all(x)) #define so_r(x) sort(all(x),greater()) #define lb lower_bound #define ub upper_bound const char nl = '\n'; int dx[4] = {1,-1,0,0}; int dy[4] = {0,0,1,-1}; int bit_cnt(int x){ return __builtin_popcount(x); } ll bex(ll a, ll b, ll mod = 1e9 + 7){ll res = 1LL; while(b){ if (b&1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;} template bool chmax(t&a,u b){if(a bool chmin(t&a,u b){if(b divisor(ll x){ vector ans; for (ll i = 1; i * i <= x; i++){ if (x % i == 0){ ans.push_back(i); if (x / i != i) ans.push_back(x/i); } } return ans; } vector divisor_of_square(ll x){ set st; vl div = divisor(x); rep(i,0,sz(div)-1) rep(j,i,sz(div)-1) st.insert(div[i] * div[j]); vl ans; each(st,y) ans.push_back(y); return ans; } void solve(){ ll P,Q; cin >> P >> Q; ll G = __gcd(P,Q); P /= G, Q /= G; vector> ans; vl div = divisor_of_square(Q); each(div, d){ // cout << d << nl; ll dd = Q * Q / d; if ( (d + Q) % P == 0 && (dd + Q) % P == 0) { ans.push_back( {(d + Q) / P, (dd + Q) / P}); } } cout << sz(ans) << nl; each(ans,v) cout << v[0] << ' ' << v[1] << nl; } void test() { ll mx = 0; rep(i,0.9e7,(int)1e7){ // chmax(mx, sz(factorization(i))); } cout << mx << nl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; // test(); while (t--){ solve(); } }