#include #include using namespace atcoder; using namespace std; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll mod=998244353; ll inf=30000000000000000;//10^17 int main(){ ll p,q; cin >> p >> q; ll ans=0; vector>a; for (ll i = max(q/p,1LL); i >=0; i++) { ll x=q*i,y=p*i-q; if (y<=0) { continue; } if (i*y>=x) { ll sz=a.size(); for (ll j = 0; j < sz; j++) { a.push_back({a[j].second,a[j].first}); } if (i*y==x) { a.push_back({i,i}); ans*=2; ans++; break; }else{ ans*=2; break; } } if (x%y==0) { ans++; a.push_back({i,x/y}); } } cout << ans << endl; sort(a.begin(),a.end()); for (ll i = 0; i < a.size(); i++) { cout << a[i].first << ' '<< a[i].second << endl; } }