import java.util.Scanner;

public class Main {

	// c < d
	public static long eukleides(long c, long d){
		if(d % c == 0){
			return c;
		}

		long mod = d % c;

		return eukleides(mod, c);
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		// input
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextInt();
		long d = scan.nextInt();
		if(c > d){
			long temp = c;
			c = d;
			d = temp;
		}

		long gcd = eukleides(c, d);
		long lcm = (c * d) / gcd;
		long answer = b - b / c - b / d + b / lcm;
		answer -= a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / lcm;

		System.out.println(answer);

	}
}


/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