import java.util.Scanner;

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

		long a = sc.nextLong();
		long b = sc.nextLong();

		long c = sc.nextLong();
		long d = sc.nextLong();

		long lcm = c * d / gcd(c, d);

		long u = b - a + 1;
		long mC = b / c - (a - 1) / c;
		long mD = b / d - (a - 1) / d;
		long mCD = b / lcm - (a - 1) / lcm;

		long ans = u - mC - mD + mCD;

		System.out.println(ans);

		sc.close();
	}

	static long gcd(long m, long n) {
		long tmp;
		while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		return n;
	}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		long c = sc.nextLong();
		long d = sc.nextLong();

		long lcm = c * d / gcd(c, d);

		long u = b - a + 1;
		long mC = b / c - (a - 1) / c;
		long mD = b / d - (a - 1) / d;
		long mCD = b / lcm - (a - 1) / lcm;

		long ans = u - mC - mD + mCD;

		System.out.println(ans);

		sc.close();
	}

	static long gcd(long m, long n) {
		long tmp;
		while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		return n;
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		long c = sc.nextLong();
		long d = sc.nextLong();

		long lcm = c * d / gcd(c, d);

		long u = b - a + 1;
		long mC = b / c - (a - 1) / c;
		long mD = b / d - (a - 1) / d;
		long mCD = b / lcm - (a - 1) / lcm;

		long ans = u - mC - mD + mCD;

		System.out.println(ans);

		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();

		long c = sc.nextLong();
		long d = sc.nextLong();

		long lcm = c * d / gcd(c, d);

		long u = b - a + 1;
		long mC = b / c - (a - 1) / c;
		long mD = b / d - (a - 1) / d;
		long mCD = b / lcm - (a - 1) / lcm;

		long ans = u - mC - mD + mCD;

		System.out.println(ans);

		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong(); a sc.nextLong() sc.nextLong sc long b = sc.nextLong(); b sc.nextLong() sc.nextLong sc long c = sc.nextLong(); c sc.nextLong() sc.nextLong sc long d = sc.nextLong(); d sc.nextLong() sc.nextLong sc long lcm = c * d / gcd(c, d); lcm c * d / gcd(c, d) c * d c d gcd(c, d) gcd c d long u = b - a + 1; u b - a + 1 b - a b a 1 long mC = b / c - (a - 1) / c; mC b / c - (a - 1) / c b / c b c (a - 1) / c (a - 1) a 1 c long mD = b / d - (a - 1) / d; mD b / d - (a - 1) / d b / d b d (a - 1) / d (a - 1) a 1 d long mCD = b / lcm - (a - 1) / lcm; mCD b / lcm - (a - 1) / lcm b / lcm b lcm (a - 1) / lcm (a - 1) a 1 lcm long ans = u - mC - mD + mCD; ans u - mC - mD + mCD u - mC - mD u - mC - mD u mC mD mCD System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc String[] args args static long gcd(long m, long n) {
		long tmp;
		while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		return n;
	} gcd {
		long tmp;
		while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		}
		return n;
	} long tmp; tmp while (m % n != 0) {
			tmp = n;
			n = m % n;
			m = tmp;
		} m % n != 0 m % n m n 0 {
			tmp = n;
			n = m % n;
			m = tmp;
		} tmp = n tmp n n = m % n n m % n m n m = tmp m tmp return n; n long m m long n n
import java.util.Scanner;

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

		long a = sc.nextLong();
		long b = sc.nextLong();

		long c = sc.nextLong();
		long d = sc.nextLong();

		long lcm = c * d / gcd(c, d);

		long u = b - a + 1;
		long mC = b / c - (a - 1) / c;
		long mD = b / d - (a - 1) / d;
		long mCD = b / lcm - (a - 1) / lcm;

		long ans = u - mC - mD + mCD;

		System.out.println(ans);

		sc.close();
	}

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