import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		System.out.println(solve(a, b, c, d));
		in.close();
	}

	private static long solve(long a, long b, long c, long d) {
		long r = 0;
		r += (b / c);
		r -= ((a - 1) / c);
		r += (b / d);
		r -= ((a - 1) / d);
		long x = gcm(c, d);
		x = c * d / x;
		r -= (b / x);
		r += ((a - 1) / x);
		return b - a + 1 - r;
	}

	private static long gcm(long c, long d) {
		if (c < d) {
			long x = c;
			c = d;
			d = x;
		}
		if (c % d == 0)
			return d;
		return gcm(d, c % d);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Arrays; Arrays java.util import java.util.Comparator; Comparator java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		System.out.println(solve(a, b, c, d));
		in.close();
	}

	private static long solve(long a, long b, long c, long d) {
		long r = 0;
		r += (b / c);
		r -= ((a - 1) / c);
		r += (b / d);
		r -= ((a - 1) / d);
		long x = gcm(c, d);
		x = c * d / x;
		r -= (b / x);
		r += ((a - 1) / x);
		return b - a + 1 - r;
	}

	private static long gcm(long c, long d) {
		if (c < d) {
			long x = c;
			c = d;
			d = x;
		}
		if (c % d == 0)
			return d;
		return gcm(d, c % d);
	}
} Main public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		System.out.println(solve(a, b, c, d));
		in.close();
	} main {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		System.out.println(solve(a, b, c, d));
		in.close();
	} Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in))); in new Scanner(new BufferedReader(new InputStreamReader(System.in))) long a = in.nextLong(); a in.nextLong() in.nextLong in long b = in.nextLong(); b in.nextLong() in.nextLong in long c = in.nextLong(); c in.nextLong() in.nextLong in long d = in.nextLong(); d in.nextLong() in.nextLong in System.out.println(solve(a, b, c, d)) System.out.println System.out System System.out solve(a, b, c, d) solve a b c d in.close() in.close in String[] args args private static long solve(long a, long b, long c, long d) {
		long r = 0;
		r += (b / c);
		r -= ((a - 1) / c);
		r += (b / d);
		r -= ((a - 1) / d);
		long x = gcm(c, d);
		x = c * d / x;
		r -= (b / x);
		r += ((a - 1) / x);
		return b - a + 1 - r;
	} solve {
		long r = 0;
		r += (b / c);
		r -= ((a - 1) / c);
		r += (b / d);
		r -= ((a - 1) / d);
		long x = gcm(c, d);
		x = c * d / x;
		r -= (b / x);
		r += ((a - 1) / x);
		return b - a + 1 - r;
	} long r = 0; r 0 r += (b / c) r (b / c) b c r -= ((a - 1) / c) r ((a - 1) / c) (a - 1) a 1 c r += (b / d) r (b / d) b d r -= ((a - 1) / d) r ((a - 1) / d) (a - 1) a 1 d long x = gcm(c, d); x gcm(c, d) gcm c d x = c * d / x x c * d / x c * d c d x r -= (b / x) r (b / x) b x r += ((a - 1) / x) r ((a - 1) / x) (a - 1) a 1 x return b - a + 1 - r; b - a + 1 - r b - a + 1 b - a b a 1 r long a a long b b long c c long d d private static long gcm(long c, long d) {
		if (c < d) {
			long x = c;
			c = d;
			d = x;
		}
		if (c % d == 0)
			return d;
		return gcm(d, c % d);
	} gcm {
		if (c < d) {
			long x = c;
			c = d;
			d = x;
		}
		if (c % d == 0)
			return d;
		return gcm(d, c % d);
	} if (c < d) {
			long x = c;
			c = d;
			d = x;
		} c < d c d {
			long x = c;
			c = d;
			d = x;
		} long x = c; x c c = d c d d = x d x if (c % d == 0)
			return d; c % d == 0 c % d c d 0 return d; d return gcm(d, c % d); gcm(d, c % d) gcm d c % d c d long c c long d d public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		System.out.println(solve(a, b, c, d));
		in.close();
	}

	private static long solve(long a, long b, long c, long d) {
		long r = 0;
		r += (b / c);
		r -= ((a - 1) / c);
		r += (b / d);
		r -= ((a - 1) / d);
		long x = gcm(c, d);
		x = c * d / x;
		r -= (b / x);
		r += ((a - 1) / x);
		return b - a + 1 - r;
	}

	private static long gcm(long c, long d) {
		if (c < d) {
			long x = c;
			c = d;
			d = x;
		}
		if (c % d == 0)
			return d;
		return gcm(d, c % d);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		System.out.println(solve(a, b, c, d));
		in.close();
	}

	private static long solve(long a, long b, long c, long d) {
		long r = 0;
		r += (b / c);
		r -= ((a - 1) / c);
		r += (b / d);
		r -= ((a - 1) / d);
		long x = gcm(c, d);
		x = c * d / x;
		r -= (b / x);
		r += ((a - 1) / x);
		return b - a + 1 - r;
	}

	private static long gcm(long c, long d) {
		if (c < d) {
			long x = c;
			c = d;
			d = x;
		}
		if (c % d == 0)
			return d;
		return gcm(d, c % d);
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		long a = in.nextLong();
		long b = in.nextLong();
		long c = in.nextLong();
		long d = in.nextLong();
		System.out.println(solve(a, b, c, d));
		in.close();
	}

	private static long solve(long a, long b, long c, long d) {
		long r = 0;
		r += (b / c);
		r -= ((a - 1) / c);
		r += (b / d);
		r -= ((a - 1) / d);
		long x = gcm(c, d);
		x = c * d / x;
		r -= (b / x);
		r += ((a - 1) / x);
		return b - a + 1 - r;
	}

	private static long gcm(long c, long d) {
		if (c < d) {
			long x = c;
			c = d;
			d = x;
		}
		if (c % d == 0)
			return d;
		return gcm(d, c % d);
	}
}
