import 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 x = getCount(a - 1, c, d);
		long y = getCount(b, c, d);
		System.out.println(b - a + 1 - (y - x));
	}
	
	static long getCount(long x, long y, long z) { // x以内で、yかzで割り切れる数
		long ans = x / y;
		ans += x / z;
		ans -= x / (y * z / gcd(y, z));
		return ans; 
	}
	
	static long gcd(long x, long y) {
		if (x % y == 0) {
			return y;
		}
		return gcd(y, x % y);
	}
} import java.util.*; util.* java 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 x = getCount(a - 1, c, d);
		long y = getCount(b, c, d);
		System.out.println(b - a + 1 - (y - x));
	}
	
	static long getCount(long x, long y, long z) { // x以内で、yかzで割り切れる数
		long ans = x / y;
		ans += x / z;
		ans -= x / (y * z / gcd(y, z));
		return ans; 
	}
	
	static long gcd(long x, long y) {
		if (x % y == 0) {
			return y;
		}
		return gcd(y, x % y);
	}
} 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 x = getCount(a - 1, c, d);
		long y = getCount(b, c, d);
		System.out.println(b - a + 1 - (y - x));
	} main {
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long x = getCount(a - 1, c, d);
		long y = getCount(b, c, d);
		System.out.println(b - a + 1 - (y - x));
	} 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 x = getCount(a - 1, c, d); x getCount(a - 1, c, d) getCount a - 1 a 1 c d long y = getCount(b, c, d); y getCount(b, c, d) getCount b c d System.out.println(b - a + 1 - (y - x)) System.out.println System.out System System.out b - a + 1 - (y - x) b - a + 1 b - a b a 1 (y - x) y x String[] args args static long getCount(long x, long y, long z) { // x以内で、yかzで割り切れる数
		long ans = x / y;
		ans += x / z;
		ans -= x / (y * z / gcd(y, z));
		return ans; 
	} getCount { // x以内で、yかzで割り切れる数
		long ans = x / y;
		ans += x / z;
		ans -= x / (y * z / gcd(y, z));
		return ans; 
	} long ans = x / y; ans x / y x y ans += x / z ans x / z x z ans -= x / (y * z / gcd(y, z)) ans x / (y * z / gcd(y, z)) x (y * z / gcd(y, z)) y * z y z gcd(y, z) gcd y z return ans; ans long x x long y y long z z static long gcd(long x, long y) {
		if (x % y == 0) {
			return y;
		}
		return gcd(y, x % y);
	} gcd {
		if (x % y == 0) {
			return y;
		}
		return gcd(y, x % y);
	} if (x % y == 0) {
			return y;
		} x % y == 0 x % y x y 0 {
			return y;
		} return y; y return gcd(y, x % y); gcd(y, x % y) gcd y x % y x y long x x long y y 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 x = getCount(a - 1, c, d);
		long y = getCount(b, c, d);
		System.out.println(b - a + 1 - (y - x));
	}
	
	static long getCount(long x, long y, long z) { // x以内で、yかzで割り切れる数
		long ans = x / y;
		ans += x / z;
		ans -= x / (y * z / gcd(y, z));
		return ans; 
	}
	
	static long gcd(long x, long y) {
		if (x % y == 0) {
			return y;
		}
		return gcd(y, x % y);
	}
} 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 x = getCount(a - 1, c, d);
		long y = getCount(b, c, d);
		System.out.println(b - a + 1 - (y - x));
	}
	
	static long getCount(long x, long y, long z) { // x以内で、yかzで割り切れる数
		long ans = x / y;
		ans += x / z;
		ans -= x / (y * z / gcd(y, z));
		return ans; 
	}
	
	static long gcd(long x, long y) {
		if (x % y == 0) {
			return y;
		}
		return gcd(y, x % y);
	}
} Main
import 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 x = getCount(a - 1, c, d);
		long y = getCount(b, c, d);
		System.out.println(b - a + 1 - (y - x));
	}
	
	static long getCount(long x, long y, long z) { // x以内で、yかzで割り切れる数
		long ans = x / y;
		ans += x / z;
		ans -= x / (y * z / gcd(y, z));
		return ans; 
	}
	
	static long gcd(long x, long y) {
		if (x % y == 0) {
			return y;
		}
		return gcd(y, x % y);
	}
}
