import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

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

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

			long s = 0;
			long t = 0;
			long u = 0;

			if (a % c == 0) {
				s = b / c - a / c + 1;
			} else {
				s = b / c - a / c;
			}

			if (a % d == 0) {
				t = b / d - a / d + 1;
			} else {
				t = b / d - a / d;
			}

			if (a % cd == 0) {
				u = b / cd - a / cd + 1;
			} else {
				u = b / cd - a / cd;
			}

			long result = (b - a + 1) - (s + t - u);

			System.out.println(result);
		}

	}

	private 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 {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

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

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

			long s = 0;
			long t = 0;
			long u = 0;

			if (a % c == 0) {
				s = b / c - a / c + 1;
			} else {
				s = b / c - a / c;
			}

			if (a % d == 0) {
				t = b / d - a / d + 1;
			} else {
				t = b / d - a / d;
			}

			if (a % cd == 0) {
				u = b / cd - a / cd + 1;
			} else {
				u = b / cd - a / cd;
			}

			long result = (b - a + 1) - (s + t - u);

			System.out.println(result);
		}

	}

	private 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 public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

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

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

			long s = 0;
			long t = 0;
			long u = 0;

			if (a % c == 0) {
				s = b / c - a / c + 1;
			} else {
				s = b / c - a / c;
			}

			if (a % d == 0) {
				t = b / d - a / d + 1;
			} else {
				t = b / d - a / d;
			}

			if (a % cd == 0) {
				u = b / cd - a / cd + 1;
			} else {
				u = b / cd - a / cd;
			}

			long result = (b - a + 1) - (s + t - u);

			System.out.println(result);
		}

	} main {

		try (Scanner sc = new Scanner(System.in)) {

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

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

			long s = 0;
			long t = 0;
			long u = 0;

			if (a % c == 0) {
				s = b / c - a / c + 1;
			} else {
				s = b / c - a / c;
			}

			if (a % d == 0) {
				t = b / d - a / d + 1;
			} else {
				t = b / d - a / d;
			}

			if (a % cd == 0) {
				u = b / cd - a / cd + 1;
			} else {
				u = b / cd - a / cd;
			}

			long result = (b - a + 1) - (s + t - u);

			System.out.println(result);
		}

	} try (Scanner sc = new Scanner(System.in)) {

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

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

			long s = 0;
			long t = 0;
			long u = 0;

			if (a % c == 0) {
				s = b / c - a / c + 1;
			} else {
				s = b / c - a / c;
			}

			if (a % d == 0) {
				t = b / d - a / d + 1;
			} else {
				t = b / d - a / d;
			}

			if (a % cd == 0) {
				u = b / cd - a / cd + 1;
			} else {
				u = b / cd - a / cd;
			}

			long result = (b - a + 1) - (s + t - u);

			System.out.println(result);
		} {

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

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

			long s = 0;
			long t = 0;
			long u = 0;

			if (a % c == 0) {
				s = b / c - a / c + 1;
			} else {
				s = b / c - a / c;
			}

			if (a % d == 0) {
				t = b / d - a / d + 1;
			} else {
				t = b / d - a / d;
			}

			if (a % cd == 0) {
				u = b / cd - a / cd + 1;
			} else {
				u = b / cd - a / cd;
			}

			long result = (b - a + 1) - (s + t - u);

			System.out.println(result);
		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) 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 cd = c * d / gcd(c, d); cd c * d / gcd(c, d) c * d c d gcd(c, d) gcd c d long s = 0; s 0 long t = 0; t 0 long u = 0; u 0 if (a % c == 0) {
				s = b / c - a / c + 1;
			} else {
				s = b / c - a / c;
			} a % c == 0 a % c a c 0 {
				s = b / c - a / c + 1;
			} s = b / c - a / c + 1 s b / c - a / c + 1 b / c - a / c b / c b c a / c a c 1 {
				s = b / c - a / c;
			} s = b / c - a / c s b / c - a / c b / c b c a / c a c if (a % d == 0) {
				t = b / d - a / d + 1;
			} else {
				t = b / d - a / d;
			} a % d == 0 a % d a d 0 {
				t = b / d - a / d + 1;
			} t = b / d - a / d + 1 t b / d - a / d + 1 b / d - a / d b / d b d a / d a d 1 {
				t = b / d - a / d;
			} t = b / d - a / d t b / d - a / d b / d b d a / d a d if (a % cd == 0) {
				u = b / cd - a / cd + 1;
			} else {
				u = b / cd - a / cd;
			} a % cd == 0 a % cd a cd 0 {
				u = b / cd - a / cd + 1;
			} u = b / cd - a / cd + 1 u b / cd - a / cd + 1 b / cd - a / cd b / cd b cd a / cd a cd 1 {
				u = b / cd - a / cd;
			} u = b / cd - a / cd u b / cd - a / cd b / cd b cd a / cd a cd long result = (b - a + 1) - (s + t - u); result (b - a + 1) - (s + t - u) (b - a + 1) b - a b a 1 (s + t - u) s + t s t u System.out.println(result) System.out.println System.out System System.out result String[] args args private 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 {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

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

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

			long s = 0;
			long t = 0;
			long u = 0;

			if (a % c == 0) {
				s = b / c - a / c + 1;
			} else {
				s = b / c - a / c;
			}

			if (a % d == 0) {
				t = b / d - a / d + 1;
			} else {
				t = b / d - a / d;
			}

			if (a % cd == 0) {
				u = b / cd - a / cd + 1;
			} else {
				u = b / cd - a / cd;
			}

			long result = (b - a + 1) - (s + t - u);

			System.out.println(result);
		}

	}

	private 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 {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

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

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

			long s = 0;
			long t = 0;
			long u = 0;

			if (a % c == 0) {
				s = b / c - a / c + 1;
			} else {
				s = b / c - a / c;
			}

			if (a % d == 0) {
				t = b / d - a / d + 1;
			} else {
				t = b / d - a / d;
			}

			if (a % cd == 0) {
				u = b / cd - a / cd + 1;
			} else {
				u = b / cd - a / cd;
			}

			long result = (b - a + 1) - (s + t - u);

			System.out.println(result);
		}

	}

	private 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 {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {

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

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

			long s = 0;
			long t = 0;
			long u = 0;

			if (a % c == 0) {
				s = b / c - a / c + 1;
			} else {
				s = b / c - a / c;
			}

			if (a % d == 0) {
				t = b / d - a / d + 1;
			} else {
				t = b / d - a / d;
			}

			if (a % cd == 0) {
				u = b / cd - a / cd + 1;
			} else {
				u = b / cd - a / cd;
			}

			long result = (b - a + 1) - (s + t - u);

			System.out.println(result);
		}

	}

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

}
