import java.util.Scanner;

public class Main {
	static long c, d;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		c = sc.nextLong();
		d = sc.nextLong();
		sc.close();

		System.out.println(f(b) - f(a - 1));
	}

	static long f(long a) {
		long x = a / c;
		long y = a / d;
		long z = a / (c * d / gcd(c, d));
		return a - x - y + z;
	}

	static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	static long c, d;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		c = sc.nextLong();
		d = sc.nextLong();
		sc.close();

		System.out.println(f(b) - f(a - 1));
	}

	static long f(long a) {
		long x = a / c;
		long y = a / d;
		long z = a / (c * d / gcd(c, d));
		return a - x - y + z;
	}

	static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
} Main static long c c d; d public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		c = sc.nextLong();
		d = sc.nextLong();
		sc.close();

		System.out.println(f(b) - f(a - 1));
	} main {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		c = sc.nextLong();
		d = sc.nextLong();
		sc.close();

		System.out.println(f(b) - f(a - 1));
	} 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 c = sc.nextLong() c sc.nextLong() sc.nextLong sc d = sc.nextLong() d sc.nextLong() sc.nextLong sc sc.close() sc.close sc System.out.println(f(b) - f(a - 1)) System.out.println System.out System System.out f(b) - f(a - 1) f(b) f b f(a - 1) f a - 1 a 1 String[] args args static long f(long a) {
		long x = a / c;
		long y = a / d;
		long z = a / (c * d / gcd(c, d));
		return a - x - y + z;
	} f {
		long x = a / c;
		long y = a / d;
		long z = a / (c * d / gcd(c, d));
		return a - x - y + z;
	} long x = a / c; x a / c a c long y = a / d; y a / d a d long z = a / (c * d / gcd(c, d)); z a / (c * d / gcd(c, d)) a (c * d / gcd(c, d)) c * d c d gcd(c, d) gcd c d return a - x - y + z; a - x - y + z a - x - y a - x - y a x y z long a a static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	} gcd {
		return b == 0 ? a : gcd(b, a % b);
	} return b == 0 ? a : gcd(b, a % b); b == 0 ? a : gcd(b, a % b) b == 0 b 0 a gcd(b, a % b) gcd b a % b a b long a a long b b public class Main {
	static long c, d;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		c = sc.nextLong();
		d = sc.nextLong();
		sc.close();

		System.out.println(f(b) - f(a - 1));
	}

	static long f(long a) {
		long x = a / c;
		long y = a / d;
		long z = a / (c * d / gcd(c, d));
		return a - x - y + z;
	}

	static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
} public class Main {
	static long c, d;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		c = sc.nextLong();
		d = sc.nextLong();
		sc.close();

		System.out.println(f(b) - f(a - 1));
	}

	static long f(long a) {
		long x = a / c;
		long y = a / d;
		long z = a / (c * d / gcd(c, d));
		return a - x - y + z;
	}

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

public class Main {
	static long c, d;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		c = sc.nextLong();
		d = sc.nextLong();
		sc.close();

		System.out.println(f(b) - f(a - 1));
	}

	static long f(long a) {
		long x = a / c;
		long y = a / d;
		long z = a / (c * d / gcd(c, d));
		return a - x - y + z;
	}

	static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}
