import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long cMulD = lcm(c, d);
		long p = b - a + 1;

		long bDivC = b / c;
		long bDivD = b / d;
		long e = b / cMulD;
		long aDivC = (a - 1) / c;
		long aDivD = (a - 1) / d;
		long f = (a - 1) / cMulD;

		long temp = bDivC + bDivD - e;
		long temp2 = aDivC + aDivD - f;

		long ans = p - (temp - temp2);

		System.out.println(ans);
	}
	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);
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long cMulD = lcm(c, d);
		long p = b - a + 1;

		long bDivC = b / c;
		long bDivD = b / d;
		long e = b / cMulD;
		long aDivC = (a - 1) / c;
		long aDivD = (a - 1) / d;
		long f = (a - 1) / cMulD;

		long temp = bDivC + bDivD - e;
		long temp2 = aDivC + aDivD - f;

		long ans = p - (temp - temp2);

		System.out.println(ans);
	}
	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);
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
} Main public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long cMulD = lcm(c, d);
		long p = b - a + 1;

		long bDivC = b / c;
		long bDivD = b / d;
		long e = b / cMulD;
		long aDivC = (a - 1) / c;
		long aDivD = (a - 1) / d;
		long f = (a - 1) / cMulD;

		long temp = bDivC + bDivD - e;
		long temp2 = aDivC + aDivD - f;

		long ans = p - (temp - temp2);

		System.out.println(ans);
	} main {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long cMulD = lcm(c, d);
		long p = b - a + 1;

		long bDivC = b / c;
		long bDivD = b / d;
		long e = b / cMulD;
		long aDivC = (a - 1) / c;
		long aDivD = (a - 1) / d;
		long f = (a - 1) / cMulD;

		long temp = bDivC + bDivD - e;
		long temp2 = aDivC + aDivD - f;

		long ans = p - (temp - temp2);

		System.out.println(ans);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long a = scan.nextLong(); a scan.nextLong() scan.nextLong scan long b = scan.nextLong(); b scan.nextLong() scan.nextLong scan long c = scan.nextLong(); c scan.nextLong() scan.nextLong scan long d = scan.nextLong(); d scan.nextLong() scan.nextLong scan long cMulD = lcm(c, d); cMulD lcm(c, d) lcm c d long p = b - a + 1; p b - a + 1 b - a b a 1 long bDivC = b / c; bDivC b / c b c long bDivD = b / d; bDivD b / d b d long e = b / cMulD; e b / cMulD b cMulD long aDivC = (a - 1) / c; aDivC (a - 1) / c (a - 1) a 1 c long aDivD = (a - 1) / d; aDivD (a - 1) / d (a - 1) a 1 d long f = (a - 1) / cMulD; f (a - 1) / cMulD (a - 1) a 1 cMulD long temp = bDivC + bDivD - e; temp bDivC + bDivD - e bDivC + bDivD bDivC bDivD e long temp2 = aDivC + aDivD - f; temp2 aDivC + aDivD - f aDivC + aDivD aDivC aDivD f long ans = p - (temp - temp2); ans p - (temp - temp2) p (temp - temp2) temp temp2 System.out.println(ans) System.out.println System.out System System.out ans String[] args args 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 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 public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long cMulD = lcm(c, d);
		long p = b - a + 1;

		long bDivC = b / c;
		long bDivD = b / d;
		long e = b / cMulD;
		long aDivC = (a - 1) / c;
		long aDivD = (a - 1) / d;
		long f = (a - 1) / cMulD;

		long temp = bDivC + bDivD - e;
		long temp2 = aDivC + aDivD - f;

		long ans = p - (temp - temp2);

		System.out.println(ans);
	}
	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);
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
} public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long cMulD = lcm(c, d);
		long p = b - a + 1;

		long bDivC = b / c;
		long bDivD = b / d;
		long e = b / cMulD;
		long aDivC = (a - 1) / c;
		long aDivD = (a - 1) / d;
		long f = (a - 1) / cMulD;

		long temp = bDivC + bDivD - e;
		long temp2 = aDivC + aDivD - f;

		long ans = p - (temp - temp2);

		System.out.println(ans);
	}
	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);
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
} Main
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();

		long cMulD = lcm(c, d);
		long p = b - a + 1;

		long bDivC = b / c;
		long bDivD = b / d;
		long e = b / cMulD;
		long aDivC = (a - 1) / c;
		long aDivD = (a - 1) / d;
		long f = (a - 1) / cMulD;

		long temp = bDivC + bDivD - e;
		long temp2 = aDivC + aDivD - f;

		long ans = p - (temp - temp2);

		System.out.println(ans);
	}
	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);
	}
	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}
}
