import 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();
		sc.close();

		// Cで割り切れる数
		long divideC = (B / C) - ((A - 1) / C);
		// Dで割り切れる数
		long divideD = (B / D) - ((A - 1) / D);
		// CとDの最小公倍数で割り切れる数
		long lcm = calcLcm(C, D);
		long divideLcm = (B / lcm) - ((A - 1) / lcm);
		System.out.println((B - (A - 1)) - (divideC + divideD - divideLcm));
	}

	// 最大公約数を求める。
	public static long calcGcd(long m, long n) {
		if (m < n) {
			long tmp = m;
			m = n;
			n = tmp;
		}
		long remainder = 0;
		while ((remainder = m % n) != 0) {
			m = n;
			n = remainder;
		}
		return n;
	}

	// 最小公倍数を求める。
	public static long calcLcm(long m, long n) {
		return m * n / calcGcd(m, n);
	}
} import java.util.*; util.* java 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();
		sc.close();

		// Cで割り切れる数
		long divideC = (B / C) - ((A - 1) / C);
		// Dで割り切れる数
		long divideD = (B / D) - ((A - 1) / D);
		// CとDの最小公倍数で割り切れる数
		long lcm = calcLcm(C, D);
		long divideLcm = (B / lcm) - ((A - 1) / lcm);
		System.out.println((B - (A - 1)) - (divideC + divideD - divideLcm));
	}

	// 最大公約数を求める。
	public static long calcGcd(long m, long n) {
		if (m < n) {
			long tmp = m;
			m = n;
			n = tmp;
		}
		long remainder = 0;
		while ((remainder = m % n) != 0) {
			m = n;
			n = remainder;
		}
		return n;
	}

	// 最小公倍数を求める。
	public static long calcLcm(long m, long n) {
		return m * n / calcGcd(m, 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();
		sc.close();

		// Cで割り切れる数
		long divideC = (B / C) - ((A - 1) / C);
		// Dで割り切れる数
		long divideD = (B / D) - ((A - 1) / D);
		// CとDの最小公倍数で割り切れる数
		long lcm = calcLcm(C, D);
		long divideLcm = (B / lcm) - ((A - 1) / lcm);
		System.out.println((B - (A - 1)) - (divideC + divideD - divideLcm));
	} main {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		sc.close();

		// Cで割り切れる数
		long divideC = (B / C) - ((A - 1) / C);
		// Dで割り切れる数
		long divideD = (B / D) - ((A - 1) / D);
		// CとDの最小公倍数で割り切れる数
		long lcm = calcLcm(C, D);
		long divideLcm = (B / lcm) - ((A - 1) / lcm);
		System.out.println((B - (A - 1)) - (divideC + divideD - divideLcm));
	} 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 sc.close() sc.close sc long divideC = (B / C) - ((A - 1) / C); divideC (B / C) - ((A - 1) / C) (B / C) B C ((A - 1) / C) (A - 1) A 1 C long divideD = (B / D) - ((A - 1) / D); divideD (B / D) - ((A - 1) / D) (B / D) B D ((A - 1) / D) (A - 1) A 1 D long lcm = calcLcm(C, D); lcm calcLcm(C, D) calcLcm C D long divideLcm = (B / lcm) - ((A - 1) / lcm); divideLcm (B / lcm) - ((A - 1) / lcm) (B / lcm) B lcm ((A - 1) / lcm) (A - 1) A 1 lcm System.out.println((B - (A - 1)) - (divideC + divideD - divideLcm)) System.out.println System.out System System.out (B - (A - 1)) - (divideC + divideD - divideLcm) (B - (A - 1)) B (A - 1) A 1 (divideC + divideD - divideLcm) divideC + divideD divideC divideD divideLcm String[] args args // 最大公約数を求める。
	public static long calcGcd(long m, long n) {
		if (m < n) {
			long tmp = m;
			m = n;
			n = tmp;
		}
		long remainder = 0;
		while ((remainder = m % n) != 0) {
			m = n;
			n = remainder;
		}
		return n;
	} calcGcd {
		if (m < n) {
			long tmp = m;
			m = n;
			n = tmp;
		}
		long remainder = 0;
		while ((remainder = m % n) != 0) {
			m = n;
			n = remainder;
		}
		return n;
	} if (m < n) {
			long tmp = m;
			m = n;
			n = tmp;
		} m < n m n {
			long tmp = m;
			m = n;
			n = tmp;
		} long tmp = m; tmp m m = n m n n = tmp n tmp long remainder = 0; remainder 0 while ((remainder = m % n) != 0) {
			m = n;
			n = remainder;
		} (remainder = m % n) != 0 (remainder = m % n) remainder m % n m n 0 {
			m = n;
			n = remainder;
		} m = n m n n = remainder n remainder return n; n long m m long n n // 最小公倍数を求める。
	public static long calcLcm(long m, long n) {
		return m * n / calcGcd(m, n);
	} calcLcm {
		return m * n / calcGcd(m, n);
	} return m * n / calcGcd(m, n); m * n / calcGcd(m, n) m * n m n calcGcd(m, n) calcGcd m n long m m long n n 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();
		sc.close();

		// Cで割り切れる数
		long divideC = (B / C) - ((A - 1) / C);
		// Dで割り切れる数
		long divideD = (B / D) - ((A - 1) / D);
		// CとDの最小公倍数で割り切れる数
		long lcm = calcLcm(C, D);
		long divideLcm = (B / lcm) - ((A - 1) / lcm);
		System.out.println((B - (A - 1)) - (divideC + divideD - divideLcm));
	}

	// 最大公約数を求める。
	public static long calcGcd(long m, long n) {
		if (m < n) {
			long tmp = m;
			m = n;
			n = tmp;
		}
		long remainder = 0;
		while ((remainder = m % n) != 0) {
			m = n;
			n = remainder;
		}
		return n;
	}

	// 最小公倍数を求める。
	public static long calcLcm(long m, long n) {
		return m * n / calcGcd(m, n);
	}
} 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();
		sc.close();

		// Cで割り切れる数
		long divideC = (B / C) - ((A - 1) / C);
		// Dで割り切れる数
		long divideD = (B / D) - ((A - 1) / D);
		// CとDの最小公倍数で割り切れる数
		long lcm = calcLcm(C, D);
		long divideLcm = (B / lcm) - ((A - 1) / lcm);
		System.out.println((B - (A - 1)) - (divideC + divideD - divideLcm));
	}

	// 最大公約数を求める。
	public static long calcGcd(long m, long n) {
		if (m < n) {
			long tmp = m;
			m = n;
			n = tmp;
		}
		long remainder = 0;
		while ((remainder = m % n) != 0) {
			m = n;
			n = remainder;
		}
		return n;
	}

	// 最小公倍数を求める。
	public static long calcLcm(long m, long n) {
		return m * n / calcGcd(m, n);
	}
} Main
import 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();
		sc.close();

		// Cで割り切れる数
		long divideC = (B / C) - ((A - 1) / C);
		// Dで割り切れる数
		long divideD = (B / D) - ((A - 1) / D);
		// CとDの最小公倍数で割り切れる数
		long lcm = calcLcm(C, D);
		long divideLcm = (B / lcm) - ((A - 1) / lcm);
		System.out.println((B - (A - 1)) - (divideC + divideD - divideLcm));
	}

	// 最大公約数を求める。
	public static long calcGcd(long m, long n) {
		if (m < n) {
			long tmp = m;
			m = n;
			n = tmp;
		}
		long remainder = 0;
		while ((remainder = m % n) != 0) {
			m = n;
			n = remainder;
		}
		return n;
	}

	// 最小公倍数を求める。
	public static long calcLcm(long m, long n) {
		return m * n / calcGcd(m, n);
	}
}
