import java.util.Scanner;

public 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 nu = b - a + 1;
		long nc = (a % c == 0) ? 1 + (b - a) / c : ((c - a % c) + a > b) ? 0 : 1 + (b - a - (c - a % c)) / c;
		long nd = (a % d == 0) ? 1 + (b - a) / d : ((d - a % d) + a > b) ? 0 : 1 + (b - a - (d - a % d)) / d;
		long cd = (c * d) / gcd(c, d);
		long ncd = (a % cd == 0) ? 1 + (b - a) / cd : ((cd - a % cd) + a > b) ? 0 : 1 + (b - a - (cd - a % cd)) / cd;

		System.out.println(nu - nc - nd + ncd);
	}

	private static long gcd(long a, long b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}
} import java.util.Scanner; Scanner java.util public 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 nu = b - a + 1;
		long nc = (a % c == 0) ? 1 + (b - a) / c : ((c - a % c) + a > b) ? 0 : 1 + (b - a - (c - a % c)) / c;
		long nd = (a % d == 0) ? 1 + (b - a) / d : ((d - a % d) + a > b) ? 0 : 1 + (b - a - (d - a % d)) / d;
		long cd = (c * d) / gcd(c, d);
		long ncd = (a % cd == 0) ? 1 + (b - a) / cd : ((cd - a % cd) + a > b) ? 0 : 1 + (b - a - (cd - a % cd)) / cd;

		System.out.println(nu - nc - nd + ncd);
	}

	private static long gcd(long a, long b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}
} 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 nu = b - a + 1;
		long nc = (a % c == 0) ? 1 + (b - a) / c : ((c - a % c) + a > b) ? 0 : 1 + (b - a - (c - a % c)) / c;
		long nd = (a % d == 0) ? 1 + (b - a) / d : ((d - a % d) + a > b) ? 0 : 1 + (b - a - (d - a % d)) / d;
		long cd = (c * d) / gcd(c, d);
		long ncd = (a % cd == 0) ? 1 + (b - a) / cd : ((cd - a % cd) + a > b) ? 0 : 1 + (b - a - (cd - a % cd)) / cd;

		System.out.println(nu - nc - nd + ncd);
	} main {
		Scanner sc = new Scanner(System.in);

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

		long nu = b - a + 1;
		long nc = (a % c == 0) ? 1 + (b - a) / c : ((c - a % c) + a > b) ? 0 : 1 + (b - a - (c - a % c)) / c;
		long nd = (a % d == 0) ? 1 + (b - a) / d : ((d - a % d) + a > b) ? 0 : 1 + (b - a - (d - a % d)) / d;
		long cd = (c * d) / gcd(c, d);
		long ncd = (a % cd == 0) ? 1 + (b - a) / cd : ((cd - a % cd) + a > b) ? 0 : 1 + (b - a - (cd - a % cd)) / cd;

		System.out.println(nu - nc - nd + ncd);
	} 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 nu = b - a + 1; nu b - a + 1 b - a b a 1 long nc = (a % c == 0) ? 1 + (b - a) / c : ((c - a % c) + a > b) ? 0 : 1 + (b - a - (c - a % c)) / c; nc (a % c == 0) ? 1 + (b - a) / c : ((c - a % c) + a > b) ? 0 : 1 + (b - a - (c - a % c)) / c (a % c == 0) a % c a c 0 1 + (b - a) / c 1 (b - a) / c (b - a) b a c ((c - a % c) + a > b) ? 0 : 1 + (b - a - (c - a % c)) / c ((c - a % c) + a > b) (c - a % c) + a (c - a % c) c a % c a c a b 0 1 + (b - a - (c - a % c)) / c 1 (b - a - (c - a % c)) / c (b - a - (c - a % c)) b - a - (c - a % c) b a (c - a % c) c a % c a c c long nd = (a % d == 0) ? 1 + (b - a) / d : ((d - a % d) + a > b) ? 0 : 1 + (b - a - (d - a % d)) / d; nd (a % d == 0) ? 1 + (b - a) / d : ((d - a % d) + a > b) ? 0 : 1 + (b - a - (d - a % d)) / d (a % d == 0) a % d a d 0 1 + (b - a) / d 1 (b - a) / d (b - a) b a d ((d - a % d) + a > b) ? 0 : 1 + (b - a - (d - a % d)) / d ((d - a % d) + a > b) (d - a % d) + a (d - a % d) d a % d a d a b 0 1 + (b - a - (d - a % d)) / d 1 (b - a - (d - a % d)) / d (b - a - (d - a % d)) b - a - (d - a % d) b a (d - a % d) d a % d a d d long cd = (c * d) / gcd(c, d); cd (c * d) / gcd(c, d) (c * d) c d gcd(c, d) gcd c d long ncd = (a % cd == 0) ? 1 + (b - a) / cd : ((cd - a % cd) + a > b) ? 0 : 1 + (b - a - (cd - a % cd)) / cd; ncd (a % cd == 0) ? 1 + (b - a) / cd : ((cd - a % cd) + a > b) ? 0 : 1 + (b - a - (cd - a % cd)) / cd (a % cd == 0) a % cd a cd 0 1 + (b - a) / cd 1 (b - a) / cd (b - a) b a cd ((cd - a % cd) + a > b) ? 0 : 1 + (b - a - (cd - a % cd)) / cd ((cd - a % cd) + a > b) (cd - a % cd) + a (cd - a % cd) cd a % cd a cd a b 0 1 + (b - a - (cd - a % cd)) / cd 1 (b - a - (cd - a % cd)) / cd (b - a - (cd - a % cd)) b - a - (cd - a % cd) b a (cd - a % cd) cd a % cd a cd cd System.out.println(nu - nc - nd + ncd) System.out.println System.out System System.out nu - nc - nd + ncd nu - nc - nd nu - nc - nd nu nc nd ncd String[] args args private static long gcd(long a, long b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	} gcd {
		if (b == 0) return a;
		return gcd(b, a % b);
	} if (b == 0) return a; b == 0 b 0 return a; a return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b long a a long b b public 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 nu = b - a + 1;
		long nc = (a % c == 0) ? 1 + (b - a) / c : ((c - a % c) + a > b) ? 0 : 1 + (b - a - (c - a % c)) / c;
		long nd = (a % d == 0) ? 1 + (b - a) / d : ((d - a % d) + a > b) ? 0 : 1 + (b - a - (d - a % d)) / d;
		long cd = (c * d) / gcd(c, d);
		long ncd = (a % cd == 0) ? 1 + (b - a) / cd : ((cd - a % cd) + a > b) ? 0 : 1 + (b - a - (cd - a % cd)) / cd;

		System.out.println(nu - nc - nd + ncd);
	}

	private static long gcd(long a, long b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}
} public 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 nu = b - a + 1;
		long nc = (a % c == 0) ? 1 + (b - a) / c : ((c - a % c) + a > b) ? 0 : 1 + (b - a - (c - a % c)) / c;
		long nd = (a % d == 0) ? 1 + (b - a) / d : ((d - a % d) + a > b) ? 0 : 1 + (b - a - (d - a % d)) / d;
		long cd = (c * d) / gcd(c, d);
		long ncd = (a % cd == 0) ? 1 + (b - a) / cd : ((cd - a % cd) + a > b) ? 0 : 1 + (b - a - (cd - a % cd)) / cd;

		System.out.println(nu - nc - nd + ncd);
	}

	private static long gcd(long a, long b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}
} Main
import java.util.Scanner;

public 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 nu = b - a + 1;
		long nc = (a % c == 0) ? 1 + (b - a) / c : ((c - a % c) + a > b) ? 0 : 1 + (b - a - (c - a % c)) / c;
		long nd = (a % d == 0) ? 1 + (b - a) / d : ((d - a % d) + a > b) ? 0 : 1 + (b - a - (d - a % d)) / d;
		long cd = (c * d) / gcd(c, d);
		long ncd = (a % cd == 0) ? 1 + (b - a) / cd : ((cd - a % cd) + a > b) ? 0 : 1 + (b - a - (cd - a % cd)) / cd;

		System.out.println(nu - nc - nd + ncd);
	}

	private static long gcd(long a, long b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}
}
