import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long cd = lcm(c, d);
		long cnum, dnum, cdnum, ans;
		cnum = b / c - (a - 1) / c;
		dnum = b / d - (a - 1) / d;
		cdnum = b / cd - (a - 1) / cd;
		ans = b - a + 1 - cnum - dnum + cdnum;
		System.out.println(ans);
	}

	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);
	}

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

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long cd = lcm(c, d);
		long cnum, dnum, cdnum, ans;
		cnum = b / c - (a - 1) / c;
		dnum = b / d - (a - 1) / d;
		cdnum = b / cd - (a - 1) / cd;
		ans = b - a + 1 - cnum - dnum + cdnum;
		System.out.println(ans);
	}

	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);
	}

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

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long cd = lcm(c, d);
		long cnum, dnum, cdnum, ans;
		cnum = b / c - (a - 1) / c;
		dnum = b / d - (a - 1) / d;
		cdnum = b / cd - (a - 1) / cd;
		ans = b - a + 1 - cnum - dnum + cdnum;
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long cd = lcm(c, d);
		long cnum, dnum, cdnum, ans;
		cnum = b / c - (a - 1) / c;
		dnum = b / d - (a - 1) / d;
		cdnum = b / cd - (a - 1) / cd;
		ans = b - a + 1 - cnum - dnum + cdnum;
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder sb = new StringBuilder(); sb new StringBuilder() long a = sc.nextLong(); a sc.nextLong() sc.nextLong sc long b = sc.nextLong(); b sc.nextLong() sc.nextLong sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc int d = sc.nextInt(); d sc.nextInt() sc.nextInt sc long cd = lcm(c, d); cd lcm(c, d) lcm c d long cnum cnum dnum dnum cdnum cdnum ans; ans cnum = b / c - (a - 1) / c cnum b / c - (a - 1) / c b / c b c (a - 1) / c (a - 1) a 1 c dnum = b / d - (a - 1) / d dnum b / d - (a - 1) / d b / d b d (a - 1) / d (a - 1) a 1 d cdnum = b / cd - (a - 1) / cd cdnum b / cd - (a - 1) / cd b / cd b cd (a - 1) / cd (a - 1) a 1 cd ans = b - a + 1 - cnum - dnum + cdnum ans b - a + 1 - cnum - dnum + cdnum b - a + 1 - cnum - dnum b - a + 1 - cnum - dnum b - a + 1 b - a b a 1 cnum dnum cdnum System.out.println(ans) System.out.println System.out System System.out ans 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 private 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 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long cd = lcm(c, d);
		long cnum, dnum, cdnum, ans;
		cnum = b / c - (a - 1) / c;
		dnum = b / d - (a - 1) / d;
		cdnum = b / cd - (a - 1) / cd;
		ans = b - a + 1 - cnum - dnum + cdnum;
		System.out.println(ans);
	}

	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);
	}

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

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long cd = lcm(c, d);
		long cnum, dnum, cdnum, ans;
		cnum = b / c - (a - 1) / c;
		dnum = b / d - (a - 1) / d;
		cdnum = b / cd - (a - 1) / cd;
		ans = b - a + 1 - cnum - dnum + cdnum;
		System.out.println(ans);
	}

	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);
	}

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

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long a = sc.nextLong();
		long b = sc.nextLong();
		int c = sc.nextInt();
		int d = sc.nextInt();
		long cd = lcm(c, d);
		long cnum, dnum, cdnum, ans;
		cnum = b / c - (a - 1) / c;
		dnum = b / d - (a - 1) / d;
		cdnum = b / cd - (a - 1) / cd;
		ans = b - a + 1 - cnum - dnum + cdnum;
		System.out.println(ans);
	}

	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);
	}

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

}
