#include void main(void){ int A,B,a,b; scanf("%d %d %d %d",&A,&B,&a,&b); int i = 0; while( !(i % A == a && i % B == b) ){ i++; } printf("%d",i); }