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 e = lcm(c, d);

		long all = b - a + 1;
		long first = b / c - (a % c == 0 ? a / c : a / c + 1) + 1;
		long second = b / d - (a % d == 0 ? a / d : a / d + 1) + 1;
		long third = b / e - (a % e == 0 ? a / e : a / e + 1) + 1;

		System.out.println(all - first - second + third);

		sc.close();

	}

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

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

		Scanner sc = new Scanner(System.in);

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

		long all = b - a + 1;
		long first = b / c - (a % c == 0 ? a / c : a / c + 1) + 1;
		long second = b / d - (a % d == 0 ? a / d : a / d + 1) + 1;
		long third = b / e - (a % e == 0 ? a / e : a / e + 1) + 1;

		System.out.println(all - first - second + third);

		sc.close();

	}

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

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

		Scanner sc = new Scanner(System.in);

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

		long all = b - a + 1;
		long first = b / c - (a % c == 0 ? a / c : a / c + 1) + 1;
		long second = b / d - (a % d == 0 ? a / d : a / d + 1) + 1;
		long third = b / e - (a % e == 0 ? a / e : a / e + 1) + 1;

		System.out.println(all - first - second + third);

		sc.close();

	} main {

		Scanner sc = new Scanner(System.in);

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

		long all = b - a + 1;
		long first = b / c - (a % c == 0 ? a / c : a / c + 1) + 1;
		long second = b / d - (a % d == 0 ? a / d : a / d + 1) + 1;
		long third = b / e - (a % e == 0 ? a / e : a / e + 1) + 1;

		System.out.println(all - first - second + third);

		sc.close();

	} 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 e = lcm(c, d); e lcm(c, d) lcm c d long all = b - a + 1; all b - a + 1 b - a b a 1 long first = b / c - (a % c == 0 ? a / c : a / c + 1) + 1; first b / c - (a % c == 0 ? a / c : a / c + 1) + 1 b / c - (a % c == 0 ? a / c : a / c + 1) b / c b c (a % c == 0 ? a / c : a / c + 1) a % c == 0 a % c a c 0 a / c a c a / c + 1 a / c a c 1 1 long second = b / d - (a % d == 0 ? a / d : a / d + 1) + 1; second b / d - (a % d == 0 ? a / d : a / d + 1) + 1 b / d - (a % d == 0 ? a / d : a / d + 1) b / d b d (a % d == 0 ? a / d : a / d + 1) a % d == 0 a % d a d 0 a / d a d a / d + 1 a / d a d 1 1 long third = b / e - (a % e == 0 ? a / e : a / e + 1) + 1; third b / e - (a % e == 0 ? a / e : a / e + 1) + 1 b / e - (a % e == 0 ? a / e : a / e + 1) b / e b e (a % e == 0 ? a / e : a / e + 1) a % e == 0 a % e a e 0 a / e a e a / e + 1 a / e a e 1 1 System.out.println(all - first - second + third) System.out.println System.out System System.out all - first - second + third all - first - second all - first - second all first second third sc.close() sc.close sc String[] args args 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 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) {

		Scanner sc = new Scanner(System.in);

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

		long all = b - a + 1;
		long first = b / c - (a % c == 0 ? a / c : a / c + 1) + 1;
		long second = b / d - (a % d == 0 ? a / d : a / d + 1) + 1;
		long third = b / e - (a % e == 0 ? a / e : a / e + 1) + 1;

		System.out.println(all - first - second + third);

		sc.close();

	}

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

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

		Scanner sc = new Scanner(System.in);

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

		long all = b - a + 1;
		long first = b / c - (a % c == 0 ? a / c : a / c + 1) + 1;
		long second = b / d - (a % d == 0 ? a / d : a / d + 1) + 1;
		long third = b / e - (a % e == 0 ? a / e : a / e + 1) + 1;

		System.out.println(all - first - second + third);

		sc.close();

	}

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

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

		Scanner sc = new Scanner(System.in);

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

		long all = b - a + 1;
		long first = b / c - (a % c == 0 ? a / c : a / c + 1) + 1;
		long second = b / d - (a % d == 0 ? a / d : a / d + 1) + 1;
		long third = b / e - (a % e == 0 ? a / e : a / e + 1) + 1;

		System.out.println(all - first - second + third);

		sc.close();

	}

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

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

}
