import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

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 result = 0;
		long c0 = b/c - (a-1)/c;
		long d0 = b/d - (a-1)/d;
		long l = lcm(c, d);
		long cd0 = b/l - (a-1)/l;
		result = (b - a + 1) - (c0 + d0 - cd0);

		// 出力
		System.out.println(result);
		
	}
	
	static long gcd(long x, long y){
	    if(x < y){
	        long temp = x;
	        x = y;
	        y = temp;
	    }
	    if(x%y == 0) return y;
	    return gcd(y , x%y);
	}
	
	static long lcm(long x, long y){
	    return x*y/gcd(x, y);
	}
} import java.util.*; util.* java import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; import java.math.BigInteger; BigInteger java.math 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 result = 0;
		long c0 = b/c - (a-1)/c;
		long d0 = b/d - (a-1)/d;
		long l = lcm(c, d);
		long cd0 = b/l - (a-1)/l;
		result = (b - a + 1) - (c0 + d0 - cd0);

		// 出力
		System.out.println(result);
		
	}
	
	static long gcd(long x, long y){
	    if(x < y){
	        long temp = x;
	        x = y;
	        y = temp;
	    }
	    if(x%y == 0) return y;
	    return gcd(y , x%y);
	}
	
	static long lcm(long x, long y){
	    return x*y/gcd(x, y);
	}
} 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 result = 0;
		long c0 = b/c - (a-1)/c;
		long d0 = b/d - (a-1)/d;
		long l = lcm(c, d);
		long cd0 = b/l - (a-1)/l;
		result = (b - a + 1) - (c0 + d0 - cd0);

		// 出力
		System.out.println(result);
		
	} main {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		
		// 計算
		long result = 0;
		long c0 = b/c - (a-1)/c;
		long d0 = b/d - (a-1)/d;
		long l = lcm(c, d);
		long cd0 = b/l - (a-1)/l;
		result = (b - a + 1) - (c0 + d0 - cd0);

		// 出力
		System.out.println(result);
		
	} 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 result = 0; result 0 long c0 = b/c - (a-1)/c; c0 b/c - (a-1)/c b/c b c (a-1)/c (a-1) a 1 c long d0 = b/d - (a-1)/d; d0 b/d - (a-1)/d b/d b d (a-1)/d (a-1) a 1 d long l = lcm(c, d); l lcm(c, d) lcm c d long cd0 = b/l - (a-1)/l; cd0 b/l - (a-1)/l b/l b l (a-1)/l (a-1) a 1 l result = (b - a + 1) - (c0 + d0 - cd0) result (b - a + 1) - (c0 + d0 - cd0) (b - a + 1) b - a b a 1 (c0 + d0 - cd0) c0 + d0 c0 d0 cd0 System.out.println(result) System.out.println System.out System System.out result String[] args args static long gcd(long x, long y){
	    if(x < y){
	        long temp = x;
	        x = y;
	        y = temp;
	    }
	    if(x%y == 0) return y;
	    return gcd(y , x%y);
	} gcd {
	    if(x < y){
	        long temp = x;
	        x = y;
	        y = temp;
	    }
	    if(x%y == 0) return y;
	    return gcd(y , x%y);
	} if(x < y){
	        long temp = x;
	        x = y;
	        y = temp;
	    } x < y x y {
	        long temp = x;
	        x = y;
	        y = temp;
	    } long temp = x; temp x x = y x y y = temp y temp if(x%y == 0) return y; x%y == 0 x%y x y 0 return y; y return gcd(y , x%y); gcd(y , x%y) gcd y x%y x y long x x long y y static long lcm(long x, long y){
	    return x*y/gcd(x, y);
	} lcm {
	    return x*y/gcd(x, y);
	} return x*y/gcd(x, y); x*y/gcd(x, y) x*y x y gcd(x, y) gcd x y long x x long y y 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 result = 0;
		long c0 = b/c - (a-1)/c;
		long d0 = b/d - (a-1)/d;
		long l = lcm(c, d);
		long cd0 = b/l - (a-1)/l;
		result = (b - a + 1) - (c0 + d0 - cd0);

		// 出力
		System.out.println(result);
		
	}
	
	static long gcd(long x, long y){
	    if(x < y){
	        long temp = x;
	        x = y;
	        y = temp;
	    }
	    if(x%y == 0) return y;
	    return gcd(y , x%y);
	}
	
	static long lcm(long x, long y){
	    return x*y/gcd(x, y);
	}
} 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 result = 0;
		long c0 = b/c - (a-1)/c;
		long d0 = b/d - (a-1)/d;
		long l = lcm(c, d);
		long cd0 = b/l - (a-1)/l;
		result = (b - a + 1) - (c0 + d0 - cd0);

		// 出力
		System.out.println(result);
		
	}
	
	static long gcd(long x, long y){
	    if(x < y){
	        long temp = x;
	        x = y;
	        y = temp;
	    }
	    if(x%y == 0) return y;
	    return gcd(y , x%y);
	}
	
	static long lcm(long x, long y){
	    return x*y/gcd(x, y);
	}
} Main
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

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 result = 0;
		long c0 = b/c - (a-1)/c;
		long d0 = b/d - (a-1)/d;
		long l = lcm(c, d);
		long cd0 = b/l - (a-1)/l;
		result = (b - a + 1) - (c0 + d0 - cd0);

		// 出力
		System.out.println(result);
		
	}
	
	static long gcd(long x, long y){
	    if(x < y){
	        long temp = x;
	        x = y;
	        y = temp;
	    }
	    if(x%y == 0) return y;
	    return gcd(y , x%y);
	}
	
	static long lcm(long x, long y){
	    return x*y/gcd(x, y);
	}
}
