import java.util.Scanner;

public class Main {
	static  long A, B, C, D;
	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 ans = f(b, c, d) - f(a - 1, c, d);
		System.out.println(ans);
	}

	static long f(long x, long c, long d) {
		long res = x;
		res -= x / c;
		res -= x / d;
		res += x / lcm(c, d);
		return res;
	}

	static long lcm(long a, long b) { return a / gcd(a, b) * b; }
	static long gcd(long m, long n) {
		if (m < n) return gcd(n, m);
		if (n == 0) return m;
		return gcd(n, m % n);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	static  long A, B, C, D;
	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 ans = f(b, c, d) - f(a - 1, c, d);
		System.out.println(ans);
	}

	static long f(long x, long c, long d) {
		long res = x;
		res -= x / c;
		res -= x / d;
		res += x / lcm(c, d);
		return res;
	}

	static long lcm(long a, long b) { return a / gcd(a, b) * b; }
	static long gcd(long m, long n) {
		if (m < n) return gcd(n, m);
		if (n == 0) return m;
		return gcd(n, m % n);
	}
} Main static  long A A B B C C D; D 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 ans = f(b, c, d) - f(a - 1, c, d);
		System.out.println(ans);
	} 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 ans = f(b, c, d) - f(a - 1, c, d);
		System.out.println(ans);
	} 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 ans = f(b, c, d) - f(a - 1, c, d); ans f(b, c, d) - f(a - 1, c, d) f(b, c, d) f b c d f(a - 1, c, d) f a - 1 a 1 c d System.out.println(ans) System.out.println System.out System System.out ans String[] args args static long f(long x, long c, long d) {
		long res = x;
		res -= x / c;
		res -= x / d;
		res += x / lcm(c, d);
		return res;
	} f {
		long res = x;
		res -= x / c;
		res -= x / d;
		res += x / lcm(c, d);
		return res;
	} long res = x; res x res -= x / c res x / c x c res -= x / d res x / d x d res += x / lcm(c, d) res x / lcm(c, d) x lcm(c, d) lcm c d return res; res long x x long c c long d d static long lcm(long a, long b) { return a / gcd(a, b) * b; } lcm { return a / gcd(a, b) * b; } return a / gcd(a, b) * b; a / gcd(a, b) * b a / gcd(a, b) a gcd(a, b) gcd a b b long a a long b b static long gcd(long m, long n) {
		if (m < n) return gcd(n, m);
		if (n == 0) return m;
		return gcd(n, m % n);
	} gcd {
		if (m < n) return gcd(n, m);
		if (n == 0) return m;
		return gcd(n, m % n);
	} if (m < n) return gcd(n, m); m < n m n return gcd(n, m); gcd(n, m) gcd n m if (n == 0) return m; n == 0 n 0 return m; m return gcd(n, m % n); gcd(n, m % n) gcd n m % n m n long m m long n n public class Main {
	static  long A, B, C, D;
	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 ans = f(b, c, d) - f(a - 1, c, d);
		System.out.println(ans);
	}

	static long f(long x, long c, long d) {
		long res = x;
		res -= x / c;
		res -= x / d;
		res += x / lcm(c, d);
		return res;
	}

	static long lcm(long a, long b) { return a / gcd(a, b) * b; }
	static long gcd(long m, long n) {
		if (m < n) return gcd(n, m);
		if (n == 0) return m;
		return gcd(n, m % n);
	}
} public class Main {
	static  long A, B, C, D;
	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 ans = f(b, c, d) - f(a - 1, c, d);
		System.out.println(ans);
	}

	static long f(long x, long c, long d) {
		long res = x;
		res -= x / c;
		res -= x / d;
		res += x / lcm(c, d);
		return res;
	}

	static long lcm(long a, long b) { return a / gcd(a, b) * b; }
	static long gcd(long m, long n) {
		if (m < n) return gcd(n, m);
		if (n == 0) return m;
		return gcd(n, m % n);
	}
} Main
import java.util.Scanner;

public class Main {
	static  long A, B, C, D;
	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 ans = f(b, c, d) - f(a - 1, c, d);
		System.out.println(ans);
	}

	static long f(long x, long c, long d) {
		long res = x;
		res -= x / c;
		res -= x / d;
		res += x / lcm(c, d);
		return res;
	}

	static long lcm(long a, long b) { return a / gcd(a, b) * b; }
	static long gcd(long m, long n) {
		if (m < n) return gcd(n, m);
		if (n == 0) return m;
		return gcd(n, m % n);
	}
}