import java.util.Scanner;

public class Main {

	static long a, b;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		a = sc.nextLong();
		b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		System.out.println(b - a + 1 - (calc(c) + calc(d) - calc(lcm(c, d))));

	}

	static long calc(long divide) {
		return b / divide - (a - 1) / divide;
	}

	static long gcd(long m, long n) {
		if (m < n)
			return gcd(n, m);
		if (n == 0)
			return m;
		return gcd(n, m % n);
	}

	static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

} import java.util.Scanner; Scanner java.util public class Main {

	static long a, b;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		a = sc.nextLong();
		b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		System.out.println(b - a + 1 - (calc(c) + calc(d) - calc(lcm(c, d))));

	}

	static long calc(long divide) {
		return b / divide - (a - 1) / divide;
	}

	static long gcd(long m, long n) {
		if (m < n)
			return gcd(n, m);
		if (n == 0)
			return m;
		return gcd(n, m % n);
	}

	static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

} Main static long a a b; b public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		a = sc.nextLong();
		b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		System.out.println(b - a + 1 - (calc(c) + calc(d) - calc(lcm(c, d))));

	} main {
		Scanner sc = new Scanner(System.in);
		a = sc.nextLong();
		b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		System.out.println(b - a + 1 - (calc(c) + calc(d) - calc(lcm(c, d))));

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) a = sc.nextLong() a sc.nextLong() sc.nextLong sc 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 System.out.println(b - a + 1 - (calc(c) + calc(d) - calc(lcm(c, d)))) System.out.println System.out System System.out b - a + 1 - (calc(c) + calc(d) - calc(lcm(c, d))) b - a + 1 b - a b a 1 (calc(c) + calc(d) - calc(lcm(c, d))) calc(c) + calc(d) calc(c) calc c calc(d) calc d calc(lcm(c, d)) calc lcm(c, d) lcm c d String[] args args static long calc(long divide) {
		return b / divide - (a - 1) / divide;
	} calc {
		return b / divide - (a - 1) / divide;
	} return b / divide - (a - 1) / divide; b / divide - (a - 1) / divide b / divide b divide (a - 1) / divide (a - 1) a 1 divide long divide divide 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 static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	} lcm {
		return m * n / gcd(m, n);
	} return m * n / gcd(m, n); m * n / gcd(m, n) m * n m n gcd(m, n) gcd m n long m m long n n public class Main {

	static long a, b;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		a = sc.nextLong();
		b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		System.out.println(b - a + 1 - (calc(c) + calc(d) - calc(lcm(c, d))));

	}

	static long calc(long divide) {
		return b / divide - (a - 1) / divide;
	}

	static long gcd(long m, long n) {
		if (m < n)
			return gcd(n, m);
		if (n == 0)
			return m;
		return gcd(n, m % n);
	}

	static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

} public class Main {

	static long a, b;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		a = sc.nextLong();
		b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		System.out.println(b - a + 1 - (calc(c) + calc(d) - calc(lcm(c, d))));

	}

	static long calc(long divide) {
		return b / divide - (a - 1) / divide;
	}

	static long gcd(long m, long n) {
		if (m < n)
			return gcd(n, m);
		if (n == 0)
			return m;
		return gcd(n, m % n);
	}

	static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

} Main
import java.util.Scanner;

public class Main {

	static long a, b;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		a = sc.nextLong();
		b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();

		System.out.println(b - a + 1 - (calc(c) + calc(d) - calc(lcm(c, d))));

	}

	static long calc(long divide) {
		return b / divide - (a - 1) / divide;
	}

	static long gcd(long m, long n) {
		if (m < n)
			return gcd(n, m);
		if (n == 0)
			return m;
		return gcd(n, m % n);
	}

	static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

}
