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 ans = (B / C - (A - 1) / C) + (B / D - (A - 1) / D) - (B / lcm(C, D) - (A - 1) / lcm(C, D));
		System.out.println(B - A - ans + 1);
	}
	
	static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	static long gcd (long a, long b) {
		return b > 0 ? gcd(b, a % b) : a;
	}
} 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 ans = (B / C - (A - 1) / C) + (B / D - (A - 1) / D) - (B / lcm(C, D) - (A - 1) / lcm(C, D));
		System.out.println(B - A - ans + 1);
	}
	
	static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	static long gcd (long a, long b) {
		return b > 0 ? gcd(b, a % b) : a;
	}
} 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 ans = (B / C - (A - 1) / C) + (B / D - (A - 1) / D) - (B / lcm(C, D) - (A - 1) / lcm(C, D));
		System.out.println(B - A - ans + 1);
	} main {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		long ans = (B / C - (A - 1) / C) + (B / D - (A - 1) / D) - (B / lcm(C, D) - (A - 1) / lcm(C, D));
		System.out.println(B - A - ans + 1);
	} 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 ans = (B / C - (A - 1) / C) + (B / D - (A - 1) / D) - (B / lcm(C, D) - (A - 1) / lcm(C, D)); ans (B / C - (A - 1) / C) + (B / D - (A - 1) / D) - (B / lcm(C, D) - (A - 1) / lcm(C, D)) (B / C - (A - 1) / C) + (B / D - (A - 1) / D) (B / C - (A - 1) / C) B / C B C (A - 1) / C (A - 1) A 1 C (B / D - (A - 1) / D) B / D B D (A - 1) / D (A - 1) A 1 D (B / lcm(C, D) - (A - 1) / lcm(C, D)) B / lcm(C, D) B lcm(C, D) lcm C D (A - 1) / lcm(C, D) (A - 1) A 1 lcm(C, D) lcm C D System.out.println(B - A - ans + 1) System.out.println System.out System System.out B - A - ans + 1 B - A - ans B - A - ans B A ans 1 String args[] args 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 static long gcd (long a, long b) {
		return b > 0 ? gcd(b, a % b) : a;
	} gcd {
		return b > 0 ? gcd(b, a % b) : a;
	} return b > 0 ? gcd(b, a % b) : a; b > 0 ? gcd(b, a % b) : a b > 0 b 0 gcd(b, a % b) gcd b a % b a b a long a a long b b 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 ans = (B / C - (A - 1) / C) + (B / D - (A - 1) / D) - (B / lcm(C, D) - (A - 1) / lcm(C, D));
		System.out.println(B - A - ans + 1);
	}
	
	static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	static long gcd (long a, long b) {
		return b > 0 ? gcd(b, a % b) : a;
	}
} 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 ans = (B / C - (A - 1) / C) + (B / D - (A - 1) / D) - (B / lcm(C, D) - (A - 1) / lcm(C, D));
		System.out.println(B - A - ans + 1);
	}
	
	static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	static long gcd (long a, long b) {
		return b > 0 ? gcd(b, a % b) : a;
	}
} 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 ans = (B / C - (A - 1) / C) + (B / D - (A - 1) / D) - (B / lcm(C, D) - (A - 1) / lcm(C, D));
		System.out.println(B - A - ans + 1);
	}
	
	static long lcm(long m, long n) {
	    return m * n / gcd(m, n);
	}

	static long gcd (long a, long b) {
		return b > 0 ? gcd(b, a % b) : a;
	}
}
