#include #include #include using namespace std; using ll=long long; vector> Prime_Factorization(ll N) { vector> R; ll e=0; while (N%2==0){ e++; N/=2; } R.push_back({2,e}); e=0; while (N%3==0){ e++; N/=3; } R.push_back({3,e}); ll p=5,f=0; while (p*p<=N) { if (N % p==0){ ll e=0; while (N % p == 0){ e++; N/=p; } R.push_back({p,e}); } p+=2+2*f; f^=1; } if (N != 1) R.push_back({N, 1}); return R; } int main(){ ll A,B,X,Y; cin >> X >> A >> Y >> B; vector> P=Prime_Factorization(X); vector> Q=Prime_Factorization(Y); map D,E; for (auto p: P){D[p.first]=A*p.second;} for (auto q: Q){E[q.first]=B*q.second;} for (auto q: E){ if (D[q.first]