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();
		 int C = scan.nextInt();
		 int D = scan.nextInt();
		 
		 long cnt_C = 0;
		 long cnt_D = 0;
		 long cnt_C_and_D = 0;
		 
		 long lcm_C_and_D = lcm (C,D);
		 
		 cnt_C = B / (long)C - calc_rounding_quo(A, (long)C) + 1;
		 cnt_D = B / (long)D - calc_rounding_quo(A, (long)D) + 1;
		 cnt_C_and_D = B / lcm_C_and_D - calc_rounding_quo(A, lcm_C_and_D) + 1;
		 
		 System.out.println(B - A + 1 - cnt_C - cnt_D + cnt_C_and_D);
		 
		 scan.close();
		 
	}
	
	public static long lcm (long m, long n) {
		return m * n / gcd(m, n);
		
	}
	
	public 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 static long calc_rounding_quo (long a, long b) {
		return (a + b - 1) / b;
		
	}

} 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();
		 int C = scan.nextInt();
		 int D = scan.nextInt();
		 
		 long cnt_C = 0;
		 long cnt_D = 0;
		 long cnt_C_and_D = 0;
		 
		 long lcm_C_and_D = lcm (C,D);
		 
		 cnt_C = B / (long)C - calc_rounding_quo(A, (long)C) + 1;
		 cnt_D = B / (long)D - calc_rounding_quo(A, (long)D) + 1;
		 cnt_C_and_D = B / lcm_C_and_D - calc_rounding_quo(A, lcm_C_and_D) + 1;
		 
		 System.out.println(B - A + 1 - cnt_C - cnt_D + cnt_C_and_D);
		 
		 scan.close();
		 
	}
	
	public static long lcm (long m, long n) {
		return m * n / gcd(m, n);
		
	}
	
	public 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 static long calc_rounding_quo (long a, long b) {
		return (a + b - 1) / b;
		
	}

} Main public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 
		 long A = scan.nextLong();
		 long B = scan.nextLong();
		 int C = scan.nextInt();
		 int D = scan.nextInt();
		 
		 long cnt_C = 0;
		 long cnt_D = 0;
		 long cnt_C_and_D = 0;
		 
		 long lcm_C_and_D = lcm (C,D);
		 
		 cnt_C = B / (long)C - calc_rounding_quo(A, (long)C) + 1;
		 cnt_D = B / (long)D - calc_rounding_quo(A, (long)D) + 1;
		 cnt_C_and_D = B / lcm_C_and_D - calc_rounding_quo(A, lcm_C_and_D) + 1;
		 
		 System.out.println(B - A + 1 - cnt_C - cnt_D + cnt_C_and_D);
		 
		 scan.close();
		 
	} main {
		 Scanner scan = new Scanner(System.in);
		 
		 long A = scan.nextLong();
		 long B = scan.nextLong();
		 int C = scan.nextInt();
		 int D = scan.nextInt();
		 
		 long cnt_C = 0;
		 long cnt_D = 0;
		 long cnt_C_and_D = 0;
		 
		 long lcm_C_and_D = lcm (C,D);
		 
		 cnt_C = B / (long)C - calc_rounding_quo(A, (long)C) + 1;
		 cnt_D = B / (long)D - calc_rounding_quo(A, (long)D) + 1;
		 cnt_C_and_D = B / lcm_C_and_D - calc_rounding_quo(A, lcm_C_and_D) + 1;
		 
		 System.out.println(B - A + 1 - cnt_C - cnt_D + cnt_C_and_D);
		 
		 scan.close();
		 
	} 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 int C = scan.nextInt(); C scan.nextInt() scan.nextInt scan int D = scan.nextInt(); D scan.nextInt() scan.nextInt scan long cnt_C = 0; cnt_C 0 long cnt_D = 0; cnt_D 0 long cnt_C_and_D = 0; cnt_C_and_D 0 long lcm_C_and_D = lcm (C,D); lcm_C_and_D lcm (C,D) lcm C D cnt_C = B / (long)C - calc_rounding_quo(A, (long)C) + 1 cnt_C B / (long)C - calc_rounding_quo(A, (long)C) + 1 B / (long)C - calc_rounding_quo(A, (long)C) B / (long)C B (long)C calc_rounding_quo(A, (long)C) calc_rounding_quo A (long)C 1 cnt_D = B / (long)D - calc_rounding_quo(A, (long)D) + 1 cnt_D B / (long)D - calc_rounding_quo(A, (long)D) + 1 B / (long)D - calc_rounding_quo(A, (long)D) B / (long)D B (long)D calc_rounding_quo(A, (long)D) calc_rounding_quo A (long)D 1 cnt_C_and_D = B / lcm_C_and_D - calc_rounding_quo(A, lcm_C_and_D) + 1 cnt_C_and_D B / lcm_C_and_D - calc_rounding_quo(A, lcm_C_and_D) + 1 B / lcm_C_and_D - calc_rounding_quo(A, lcm_C_and_D) B / lcm_C_and_D B lcm_C_and_D calc_rounding_quo(A, lcm_C_and_D) calc_rounding_quo A lcm_C_and_D 1 System.out.println(B - A + 1 - cnt_C - cnt_D + cnt_C_and_D) System.out.println System.out System System.out B - A + 1 - cnt_C - cnt_D + cnt_C_and_D B - A + 1 - cnt_C - cnt_D B - A + 1 - cnt_C - cnt_D B - A + 1 B - A B A 1 cnt_C cnt_D cnt_C_and_D scan.close() scan.close scan String[] args args public 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 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 static long calc_rounding_quo (long a, long b) {
		return (a + b - 1) / b;
		
	} calc_rounding_quo {
		return (a + b - 1) / b;
		
	} return (a + b - 1) / b; (a + b - 1) / b (a + b - 1) a + b a b 1 b long a a long b b public class Main {

	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 
		 long A = scan.nextLong();
		 long B = scan.nextLong();
		 int C = scan.nextInt();
		 int D = scan.nextInt();
		 
		 long cnt_C = 0;
		 long cnt_D = 0;
		 long cnt_C_and_D = 0;
		 
		 long lcm_C_and_D = lcm (C,D);
		 
		 cnt_C = B / (long)C - calc_rounding_quo(A, (long)C) + 1;
		 cnt_D = B / (long)D - calc_rounding_quo(A, (long)D) + 1;
		 cnt_C_and_D = B / lcm_C_and_D - calc_rounding_quo(A, lcm_C_and_D) + 1;
		 
		 System.out.println(B - A + 1 - cnt_C - cnt_D + cnt_C_and_D);
		 
		 scan.close();
		 
	}
	
	public static long lcm (long m, long n) {
		return m * n / gcd(m, n);
		
	}
	
	public 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 static long calc_rounding_quo (long a, long b) {
		return (a + b - 1) / b;
		
	}

} public class Main {

	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 
		 long A = scan.nextLong();
		 long B = scan.nextLong();
		 int C = scan.nextInt();
		 int D = scan.nextInt();
		 
		 long cnt_C = 0;
		 long cnt_D = 0;
		 long cnt_C_and_D = 0;
		 
		 long lcm_C_and_D = lcm (C,D);
		 
		 cnt_C = B / (long)C - calc_rounding_quo(A, (long)C) + 1;
		 cnt_D = B / (long)D - calc_rounding_quo(A, (long)D) + 1;
		 cnt_C_and_D = B / lcm_C_and_D - calc_rounding_quo(A, lcm_C_and_D) + 1;
		 
		 System.out.println(B - A + 1 - cnt_C - cnt_D + cnt_C_and_D);
		 
		 scan.close();
		 
	}
	
	public static long lcm (long m, long n) {
		return m * n / gcd(m, n);
		
	}
	
	public 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 static long calc_rounding_quo (long a, long b) {
		return (a + b - 1) / b;
		
	}

} 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();
		 int C = scan.nextInt();
		 int D = scan.nextInt();
		 
		 long cnt_C = 0;
		 long cnt_D = 0;
		 long cnt_C_and_D = 0;
		 
		 long lcm_C_and_D = lcm (C,D);
		 
		 cnt_C = B / (long)C - calc_rounding_quo(A, (long)C) + 1;
		 cnt_D = B / (long)D - calc_rounding_quo(A, (long)D) + 1;
		 cnt_C_and_D = B / lcm_C_and_D - calc_rounding_quo(A, lcm_C_and_D) + 1;
		 
		 System.out.println(B - A + 1 - cnt_C - cnt_D + cnt_C_and_D);
		 
		 scan.close();
		 
	}
	
	public static long lcm (long m, long n) {
		return m * n / gcd(m, n);
		
	}
	
	public 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 static long calc_rounding_quo (long a, long b) {
		return (a + b - 1) / b;
		
	}

}
