import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		
		long A, B, C, D;
		A = Long.parseLong(sc.next()) - 1;
		B = Long.parseLong(sc.next());
		C = Long.parseLong(sc.next());
		D = Long.parseLong(sc.next());
		
		int count = 0;
		long lcm = C * D / gcd(C, D);
		
		long tmpAC = A / C;
		long tmpBC = B / C;
		long tmpAD = A / D;
		long tmpBD = B / D;
		
		long tmpACD = A / lcm;
		long tmpBCD = B / lcm;
		
		long ans = tmpBC - tmpAC + tmpBD - tmpAD - (tmpBCD - tmpACD);
		
		ans = B - (A + 1) + 1 - ans;
		
		
		System.out.println(ans);

	}
	
	private static long gcd(long m, long n) {
		long tmp;
		while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		return n;
	}

}

/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz