#include using namespace std; using ll = long long; //素因数分解 template vector> prime_factor(T n) { vector> ret; T tmp=0; if(n%2==0){ tmp=0;while(n%2==0){tmp++;n/=2;} ret.push_back(make_pair(2, tmp)); } if(n%3==0){ tmp=0;while(n%3==0){tmp++;n/=3;} ret.push_back(make_pair(3, tmp)); } for (T i=5;i*i<=n;i+=4) { if(n%i==0){ tmp=0;while(n%i==0){tmp++;n/=i;} ret.push_back(make_pair(i,tmp)); } i+=2; if(n%i==0){ tmp=0;while(n%i==0){tmp++;n/=i;} ret.push_back(make_pair(i,tmp)); } } if(n!=1)ret.push_back(make_pair(n,1)); return ret; } int main(){ ll P, Q, Q2, g; cin >> P >> Q; g = __gcd(P, Q); P /= g, Q /= g; auto prime = prime_factor(Q); for(auto &&p:prime)p.second <<= 1; vector y; function dfs = [&](int i, ll v){ if(i == prime.size()){ y.push_back(v); return; } ll d = 1; for(int j = 0; j <= prime[i].second; j++){ if(j)d *= prime[i].first; dfs(i + 1, v * d); } }; dfs(0, 1); vector> ans; Q2 = Q * Q; for(auto &&v:y){ ll v1 = Q2 / v; if((v + Q) % P == 0 && (v1 + Q) % P == 0)ans.emplace_back((v + Q) / P, (v1 + Q) / P); } sort(ans.begin(), ans.end()); cout << ans.size() << '\n'; for(int i = 0; i < ans.size(); i++){ cout << ans[i].first << ' ' << ans[i].second << '\n'; } }