import java.util.Scanner;

class Main {

    public static long calc(long A, long B, long X) {
	long A_count = (A - 1) / X;
	long B_count = B / X;

	return B - A + 1 - (B_count - A_count);
    }

    public static long lcm(long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a % b) != 0) {
		a = b;
		b = temp;
	}

	return (long)(c / b);
    }
    
    public static void main(String[] args)  {
	Scanner sc = new Scanner(System.in);

	long A, B, C, D;
	A = sc.nextLong();
	B = sc.nextLong();
	C = sc.nextLong();
	D = sc.nextLong();

	long C_count = calc(A, B, C);
	long D_count = calc(A, B, D);
	long CD_count = calc(A, B, lcm(C, D));

	System.out.println(C_count + D_count - CD_count);
    }
} import java.util.Scanner; Scanner java.util class Main {

    public static long calc(long A, long B, long X) {
	long A_count = (A - 1) / X;
	long B_count = B / X;

	return B - A + 1 - (B_count - A_count);
    }

    public static long lcm(long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a % b) != 0) {
		a = b;
		b = temp;
	}

	return (long)(c / b);
    }
    
    public static void main(String[] args)  {
	Scanner sc = new Scanner(System.in);

	long A, B, C, D;
	A = sc.nextLong();
	B = sc.nextLong();
	C = sc.nextLong();
	D = sc.nextLong();

	long C_count = calc(A, B, C);
	long D_count = calc(A, B, D);
	long CD_count = calc(A, B, lcm(C, D));

	System.out.println(C_count + D_count - CD_count);
    }
} Main public static long calc(long A, long B, long X) {
	long A_count = (A - 1) / X;
	long B_count = B / X;

	return B - A + 1 - (B_count - A_count);
    } calc {
	long A_count = (A - 1) / X;
	long B_count = B / X;

	return B - A + 1 - (B_count - A_count);
    } long A_count = (A - 1) / X; A_count (A - 1) / X (A - 1) A 1 X long B_count = B / X; B_count B / X B X return B - A + 1 - (B_count - A_count); B - A + 1 - (B_count - A_count) B - A + 1 B - A B A 1 (B_count - A_count) B_count A_count long A A long B B long X X public static long lcm(long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a % b) != 0) {
		a = b;
		b = temp;
	}

	return (long)(c / b);
    } lcm {
	long temp;
	long c = a;
	c *= b;
	while((temp = a % b) != 0) {
		a = b;
		b = temp;
	}

	return (long)(c / b);
    } long temp; temp long c = a; c a c *= b c b while((temp = a % b) != 0) {
		a = b;
		b = temp;
	} (temp = a % b) != 0 (temp = a % b) temp a % b a b 0 {
		a = b;
		b = temp;
	} a = b a b b = temp b temp return (long)(c / b); (long)(c / b) c b long a a long b b public static void main(String[] args)  {
	Scanner sc = new Scanner(System.in);

	long A, B, C, D;
	A = sc.nextLong();
	B = sc.nextLong();
	C = sc.nextLong();
	D = sc.nextLong();

	long C_count = calc(A, B, C);
	long D_count = calc(A, B, D);
	long CD_count = calc(A, B, lcm(C, D));

	System.out.println(C_count + D_count - CD_count);
    } main {
	Scanner sc = new Scanner(System.in);

	long A, B, C, D;
	A = sc.nextLong();
	B = sc.nextLong();
	C = sc.nextLong();
	D = sc.nextLong();

	long C_count = calc(A, B, C);
	long D_count = calc(A, B, D);
	long CD_count = calc(A, B, lcm(C, D));

	System.out.println(C_count + D_count - CD_count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long A A B B C C D; D A = sc.nextLong() A sc.nextLong() sc.nextLong sc B = sc.nextLong() B sc.nextLong() sc.nextLong sc C = sc.nextLong() C sc.nextLong() sc.nextLong sc D = sc.nextLong() D sc.nextLong() sc.nextLong sc long C_count = calc(A, B, C); C_count calc(A, B, C) calc A B C long D_count = calc(A, B, D); D_count calc(A, B, D) calc A B D long CD_count = calc(A, B, lcm(C, D)); CD_count calc(A, B, lcm(C, D)) calc A B lcm(C, D) lcm C D System.out.println(C_count + D_count - CD_count) System.out.println System.out System System.out C_count + D_count - CD_count C_count + D_count C_count D_count CD_count String[] args args
import java.util.Scanner;

class Main {

    public static long calc(long A, long B, long X) {
	long A_count = (A - 1) / X;
	long B_count = B / X;

	return B - A + 1 - (B_count - A_count);
    }

    public static long lcm(long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a % b) != 0) {
		a = b;
		b = temp;
	}

	return (long)(c / b);
    }
    
    public static void main(String[] args)  {
	Scanner sc = new Scanner(System.in);

	long A, B, C, D;
	A = sc.nextLong();
	B = sc.nextLong();
	C = sc.nextLong();
	D = sc.nextLong();

	long C_count = calc(A, B, C);
	long D_count = calc(A, B, D);
	long CD_count = calc(A, B, lcm(C, D));

	System.out.println(C_count + D_count - CD_count);
    }
}