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 E = lcm(C,D);

		long x = 0;
		long y = 0;
		long z = 0;

		if (A%C == 0){
			x = B/C - A/C + 1;
		} else {
			x = B/C - A/C;
		}

		if (A%D == 0){
			y = B/D - A/D + 1;
		} else {
			y = B/D - A/D;
		}

		if (A%E == 0){
			z = B/E - A/E + 1;
		} else {
			z = B/E - A/E;
		}

		System.out.println(B - A + 1 - (x + y - z));
	}

	public static long gcd(long a , long b) {
		if (b==0) {
			return a;
		}
		return gcd(b,a%b);
	}

	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 sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long E = lcm(C,D);

		long x = 0;
		long y = 0;
		long z = 0;

		if (A%C == 0){
			x = B/C - A/C + 1;
		} else {
			x = B/C - A/C;
		}

		if (A%D == 0){
			y = B/D - A/D + 1;
		} else {
			y = B/D - A/D;
		}

		if (A%E == 0){
			z = B/E - A/E + 1;
		} else {
			z = B/E - A/E;
		}

		System.out.println(B - A + 1 - (x + y - z));
	}

	public static long gcd(long a , long b) {
		if (b==0) {
			return a;
		}
		return gcd(b,a%b);
	}

	private static long lcm(long m, long n) {
        return m * n / gcd(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 E = lcm(C,D);

		long x = 0;
		long y = 0;
		long z = 0;

		if (A%C == 0){
			x = B/C - A/C + 1;
		} else {
			x = B/C - A/C;
		}

		if (A%D == 0){
			y = B/D - A/D + 1;
		} else {
			y = B/D - A/D;
		}

		if (A%E == 0){
			z = B/E - A/E + 1;
		} else {
			z = B/E - A/E;
		}

		System.out.println(B - A + 1 - (x + y - z));
	} main {
		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long E = lcm(C,D);

		long x = 0;
		long y = 0;
		long z = 0;

		if (A%C == 0){
			x = B/C - A/C + 1;
		} else {
			x = B/C - A/C;
		}

		if (A%D == 0){
			y = B/D - A/D + 1;
		} else {
			y = B/D - A/D;
		}

		if (A%E == 0){
			z = B/E - A/E + 1;
		} else {
			z = B/E - A/E;
		}

		System.out.println(B - A + 1 - (x + y - z));
	} 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 E = lcm(C,D); E lcm(C,D) lcm C D long x = 0; x 0 long y = 0; y 0 long z = 0; z 0 if (A%C == 0){
			x = B/C - A/C + 1;
		} else {
			x = B/C - A/C;
		} A%C == 0 A%C A C 0 {
			x = B/C - A/C + 1;
		} x = B/C - A/C + 1 x B/C - A/C + 1 B/C - A/C B/C B C A/C A C 1 {
			x = B/C - A/C;
		} x = B/C - A/C x B/C - A/C B/C B C A/C A C if (A%D == 0){
			y = B/D - A/D + 1;
		} else {
			y = B/D - A/D;
		} A%D == 0 A%D A D 0 {
			y = B/D - A/D + 1;
		} y = B/D - A/D + 1 y B/D - A/D + 1 B/D - A/D B/D B D A/D A D 1 {
			y = B/D - A/D;
		} y = B/D - A/D y B/D - A/D B/D B D A/D A D if (A%E == 0){
			z = B/E - A/E + 1;
		} else {
			z = B/E - A/E;
		} A%E == 0 A%E A E 0 {
			z = B/E - A/E + 1;
		} z = B/E - A/E + 1 z B/E - A/E + 1 B/E - A/E B/E B E A/E A E 1 {
			z = B/E - A/E;
		} z = B/E - A/E z B/E - A/E B/E B E A/E A E System.out.println(B - A + 1 - (x + y - z)) System.out.println System.out System System.out B - A + 1 - (x + y - z) B - A + 1 B - A B A 1 (x + y - z) x + y x y z String[] args args public static long gcd(long a , long b) {
		if (b==0) {
			return a;
		}
		return gcd(b,a%b);
	} gcd {
		if (b==0) {
			return a;
		}
		return gcd(b,a%b);
	} if (b==0) {
			return a;
		} b==0 b 0 {
			return a;
		} return a; a return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b long a a long b b 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 sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long E = lcm(C,D);

		long x = 0;
		long y = 0;
		long z = 0;

		if (A%C == 0){
			x = B/C - A/C + 1;
		} else {
			x = B/C - A/C;
		}

		if (A%D == 0){
			y = B/D - A/D + 1;
		} else {
			y = B/D - A/D;
		}

		if (A%E == 0){
			z = B/E - A/E + 1;
		} else {
			z = B/E - A/E;
		}

		System.out.println(B - A + 1 - (x + y - z));
	}

	public static long gcd(long a , long b) {
		if (b==0) {
			return a;
		}
		return gcd(b,a%b);
	}

	private static long lcm(long m, long n) {
        return m * n / gcd(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 E = lcm(C,D);

		long x = 0;
		long y = 0;
		long z = 0;

		if (A%C == 0){
			x = B/C - A/C + 1;
		} else {
			x = B/C - A/C;
		}

		if (A%D == 0){
			y = B/D - A/D + 1;
		} else {
			y = B/D - A/D;
		}

		if (A%E == 0){
			z = B/E - A/E + 1;
		} else {
			z = B/E - A/E;
		}

		System.out.println(B - A + 1 - (x + y - z));
	}

	public static long gcd(long a , long b) {
		if (b==0) {
			return a;
		}
		return gcd(b,a%b);
	}

	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 sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long E = lcm(C,D);

		long x = 0;
		long y = 0;
		long z = 0;

		if (A%C == 0){
			x = B/C - A/C + 1;
		} else {
			x = B/C - A/C;
		}

		if (A%D == 0){
			y = B/D - A/D + 1;
		} else {
			y = B/D - A/D;
		}

		if (A%E == 0){
			z = B/E - A/E + 1;
		} else {
			z = B/E - A/E;
		}

		System.out.println(B - A + 1 - (x + y - z));
	}

	public static long gcd(long a , long b) {
		if (b==0) {
			return a;
		}
		return gcd(b,a%b);
	}

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