import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class B {

	public static void main(String[] args){
		Reader reader = new Reader(System.in);
		int cnt1  = reader.readInt();
		int cnt2 = reader.readInt();
		int x = reader.readInt();
		int y = reader.readInt();
		
		int lcmXY = lcm(x,y);
		
		int total = cnt1+cnt2;
		
		
			int notUseable = total/lcmXY;
			int notUseableX = total/x - notUseable;
			int notUseableY = total/y - notUseable;
			
			int extraForCnt1= Math.max(0,notUseableY-cnt1);
			int extraForCnt2 =Math.max(0, notUseableX-cnt2);
			
			
			System.out.println(total+notUseable+extraForCnt1+extraForCnt2);
		
		
		
		
		

	}
	public static int lcm (int a, int b){
		int aa=a;
		int bb=b;
		while(aa!=bb){
			while(aa<bb)
				aa+=a;
			while(bb<aa)
				bb+=b;
		}
		return aa;
	}
	public static class Reader{
		BufferedReader br;
		StringTokenizer st;
		public Reader(InputStream in){
			br = new BufferedReader(new InputStreamReader(System.in));			
		}

		public String read(){
			if(st==null || !st.hasMoreTokens()){
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

			return st.nextToken();
		}

		public String readWord(){
			return read();
		}
		public long readLong(){
			return Long.parseLong(read());
		}
		public int readInt(){
			return Integer.parseInt(read());
		}
		public double readDouble(){
			return Double.parseDouble(read());
		}
		public float readFloat(){
			return Float.parseFloat(read());
		}
	}
}
