#include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int A[3000][3]; void d(int i){ int x=A[i][0]%A[i+1][0],y=A[i][0]/A[i+1][0]; A[i+2][0]=x; A[i+2][1]=A[i][1]-y*A[i+1][1]; A[i+2][2]=A[i][2]-y*A[i+1][2]; } int main() { int p,q,a,b;cin>>p>>q>>a>>b; if(p