import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);
		long c = Long.parseLong(str[2]);
		long d = Long.parseLong(str[3]);

		System.out.println(num(b, c, d) - num(a - 1, c, d));
	}

	static long num(long n, long c, long d) {
		long G = gcd(c, d);
		long L = c / G * d;
		return n - n / c - n / d + n / L;
	}

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

	static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);
		long c = Long.parseLong(str[2]);
		long d = Long.parseLong(str[3]);

		System.out.println(num(b, c, d) - num(a - 1, c, d));
	}

	static long num(long n, long c, long d) {
		long G = gcd(c, d);
		long L = c / G * d;
		return n - n / c - n / d + n / L;
	}

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

	static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}
} Main public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);
		long c = Long.parseLong(str[2]);
		long d = Long.parseLong(str[3]);

		System.out.println(num(b, c, d) - num(a - 1, c, d));
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);
		long c = Long.parseLong(str[2]);
		long d = Long.parseLong(str[3]);

		System.out.println(num(b, c, d) - num(a - 1, c, d));
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str[] = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " long a = Long.parseLong(str[0]); a Long.parseLong(str[0]) Long.parseLong Long str[0] str 0 long b = Long.parseLong(str[1]); b Long.parseLong(str[1]) Long.parseLong Long str[1] str 1 long c = Long.parseLong(str[2]); c Long.parseLong(str[2]) Long.parseLong Long str[2] str 2 long d = Long.parseLong(str[3]); d Long.parseLong(str[3]) Long.parseLong Long str[3] str 3 System.out.println(num(b, c, d) - num(a - 1, c, d)) System.out.println System.out System System.out num(b, c, d) - num(a - 1, c, d) num(b, c, d) num b c d num(a - 1, c, d) num a - 1 a 1 c d String args[] args static long num(long n, long c, long d) {
		long G = gcd(c, d);
		long L = c / G * d;
		return n - n / c - n / d + n / L;
	} num {
		long G = gcd(c, d);
		long L = c / G * d;
		return n - n / c - n / d + n / L;
	} long G = gcd(c, d); G gcd(c, d) gcd c d long L = c / G * d; L c / G * d c / G c G d return n - n / c - n / d + n / L; n - n / c - n / d + n / L n - n / c - n / d n - n / c - n / d n n / c n c n / d n d n / L n L long n n long c c long d d static long gcd(long a, long b) {
		return b > 0 ? gcd(b, a % b) : a;
	} gcd {
		return b > 0 ? gcd(b, a % b) : a;
	} return b > 0 ? gcd(b, a % b) : a; b > 0 ? gcd(b, a % b) : a b > 0 b 0 gcd(b, a % b) gcd b a % b a b a long a a long b b static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	} lcm {
		return a * b / gcd(a, b);
	} return a * b / gcd(a, b); a * b / gcd(a, b) a * b a b gcd(a, b) gcd a b long a a long b b public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);
		long c = Long.parseLong(str[2]);
		long d = Long.parseLong(str[3]);

		System.out.println(num(b, c, d) - num(a - 1, c, d));
	}

	static long num(long n, long c, long d) {
		long G = gcd(c, d);
		long L = c / G * d;
		return n - n / c - n / d + n / L;
	}

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

	static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}
} public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);
		long c = Long.parseLong(str[2]);
		long d = Long.parseLong(str[3]);

		System.out.println(num(b, c, d) - num(a - 1, c, d));
	}

	static long num(long n, long c, long d) {
		long G = gcd(c, d);
		long L = c / G * d;
		return n - n / c - n / d + n / L;
	}

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

	static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		long a = Long.parseLong(str[0]);
		long b = Long.parseLong(str[1]);
		long c = Long.parseLong(str[2]);
		long d = Long.parseLong(str[3]);

		System.out.println(num(b, c, d) - num(a - 1, c, d));
	}

	static long num(long n, long c, long d) {
		long G = gcd(c, d);
		long L = c / G * d;
		return n - n / c - n / d + n / L;
	}

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

	static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}
}
