import java.util.Scanner;

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 koumoku = B - A + 1;

//		long kosu = koumoku - (koumoku / C) - (koumoku / D) + (koumoku / (C * D));
		long kosu = koumoku - kosu(A, B, C) - kosu(A, B, D) + kosu(A, B, lcm(C,D));
		System.out.println(kosu);
	}

	public static long kosu(long min, long max, long wari){

		long start;

		if (min % wari == 0){
			start = min;
		} else {
			start = min + (wari - min % wari);
		}

		long mod = (max - start + 1) % wari;
		long kosu = (max - start + 1) / wari;
		if (mod > 0){
			kosu += 1;
		}

		return kosu;
	}

	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	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);
	}
} import java.util.Scanner; Scanner 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 koumoku = B - A + 1;

//		long kosu = koumoku - (koumoku / C) - (koumoku / D) + (koumoku / (C * D));
		long kosu = koumoku - kosu(A, B, C) - kosu(A, B, D) + kosu(A, B, lcm(C,D));
		System.out.println(kosu);
	}

	public static long kosu(long min, long max, long wari){

		long start;

		if (min % wari == 0){
			start = min;
		} else {
			start = min + (wari - min % wari);
		}

		long mod = (max - start + 1) % wari;
		long kosu = (max - start + 1) / wari;
		if (mod > 0){
			kosu += 1;
		}

		return kosu;
	}

	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	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);
	}
} 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 koumoku = B - A + 1;

//		long kosu = koumoku - (koumoku / C) - (koumoku / D) + (koumoku / (C * D));
		long kosu = koumoku - kosu(A, B, C) - kosu(A, B, D) + kosu(A, B, lcm(C,D));
		System.out.println(kosu);
	} main {

		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long koumoku = B - A + 1;

//		long kosu = koumoku - (koumoku / C) - (koumoku / D) + (koumoku / (C * D));
		long kosu = koumoku - kosu(A, B, C) - kosu(A, B, D) + kosu(A, B, lcm(C,D));
		System.out.println(kosu);
	} 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 koumoku = B - A + 1; koumoku B - A + 1 B - A B A 1 long kosu = koumoku - kosu(A, B, C) - kosu(A, B, D) + kosu(A, B, lcm(C,D)); kosu koumoku - kosu(A, B, C) - kosu(A, B, D) + kosu(A, B, lcm(C,D)) koumoku - kosu(A, B, C) - kosu(A, B, D) koumoku - kosu(A, B, C) - kosu(A, B, D) koumoku kosu(A, B, C) kosu A B C kosu(A, B, D) kosu A B D kosu(A, B, lcm(C,D)) kosu A B lcm(C,D) lcm C D System.out.println(kosu) System.out.println System.out System System.out kosu String[] args args public static long kosu(long min, long max, long wari){

		long start;

		if (min % wari == 0){
			start = min;
		} else {
			start = min + (wari - min % wari);
		}

		long mod = (max - start + 1) % wari;
		long kosu = (max - start + 1) / wari;
		if (mod > 0){
			kosu += 1;
		}

		return kosu;
	} kosu {

		long start;

		if (min % wari == 0){
			start = min;
		} else {
			start = min + (wari - min % wari);
		}

		long mod = (max - start + 1) % wari;
		long kosu = (max - start + 1) / wari;
		if (mod > 0){
			kosu += 1;
		}

		return kosu;
	} long start; start if (min % wari == 0){
			start = min;
		} else {
			start = min + (wari - min % wari);
		} min % wari == 0 min % wari min wari 0 {
			start = min;
		} start = min start min {
			start = min + (wari - min % wari);
		} start = min + (wari - min % wari) start min + (wari - min % wari) min (wari - min % wari) wari min % wari min wari long mod = (max - start + 1) % wari; mod (max - start + 1) % wari (max - start + 1) max - start max start 1 wari long kosu = (max - start + 1) / wari; kosu (max - start + 1) / wari (max - start + 1) max - start max start 1 wari if (mod > 0){
			kosu += 1;
		} mod > 0 mod 0 {
			kosu += 1;
		} kosu += 1 kosu 1 return kosu; kosu long min min long max max long wari wari 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 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 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 koumoku = B - A + 1;

//		long kosu = koumoku - (koumoku / C) - (koumoku / D) + (koumoku / (C * D));
		long kosu = koumoku - kosu(A, B, C) - kosu(A, B, D) + kosu(A, B, lcm(C,D));
		System.out.println(kosu);
	}

	public static long kosu(long min, long max, long wari){

		long start;

		if (min % wari == 0){
			start = min;
		} else {
			start = min + (wari - min % wari);
		}

		long mod = (max - start + 1) % wari;
		long kosu = (max - start + 1) / wari;
		if (mod > 0){
			kosu += 1;
		}

		return kosu;
	}

	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	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);
	}
} 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 koumoku = B - A + 1;

//		long kosu = koumoku - (koumoku / C) - (koumoku / D) + (koumoku / (C * D));
		long kosu = koumoku - kosu(A, B, C) - kosu(A, B, D) + kosu(A, B, lcm(C,D));
		System.out.println(kosu);
	}

	public static long kosu(long min, long max, long wari){

		long start;

		if (min % wari == 0){
			start = min;
		} else {
			start = min + (wari - min % wari);
		}

		long mod = (max - start + 1) % wari;
		long kosu = (max - start + 1) / wari;
		if (mod > 0){
			kosu += 1;
		}

		return kosu;
	}

	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	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);
	}
} Main
import java.util.Scanner;

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 koumoku = B - A + 1;

//		long kosu = koumoku - (koumoku / C) - (koumoku / D) + (koumoku / (C * D));
		long kosu = koumoku - kosu(A, B, C) - kosu(A, B, D) + kosu(A, B, lcm(C,D));
		System.out.println(kosu);
	}

	public static long kosu(long min, long max, long wari){

		long start;

		if (min % wari == 0){
			start = min;
		} else {
			start = min + (wari - min % wari);
		}

		long mod = (max - start + 1) % wari;
		long kosu = (max - start + 1) / wari;
		if (mod > 0){
			kosu += 1;
		}

		return kosu;
	}

	private static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	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);
	}
}