import java.math.BigInteger;
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		BigInteger a = new BigInteger(sc.next());
		a = a.subtract(BigInteger.ONE);
		BigInteger b = new BigInteger(sc.next());
		BigInteger c = new BigInteger(sc.next());
		BigInteger d = new BigInteger(sc.next());

		BigInteger ans = b.subtract(a);

		BigInteger val = b.divide(c).subtract(a.divide(c));
		ans = ans.subtract(val);

		val = b.divide(d).subtract(a.divide(d));
		ans = ans.subtract(val);

		BigInteger divisor = c.multiply(d).divide(Divisor.gcd(c, d));
		val = b.divide(divisor).subtract(a.divide(divisor));
		ans = ans.add(val);

		System.out.println(ans);
	}
}



class Divisor{
    public static BigInteger gcd(BigInteger a, BigInteger b){
        if(b.equals(BigInteger.ZERO))return a;
        return gcd(b, a.remainder(b));
    }

    static BigInteger x, y;
    public static BigInteger extGcd(BigInteger a, BigInteger b){
        if(b.equals(BigInteger.ZERO)){
            x = BigInteger.ONE;
            y = BigInteger.ZERO;
            return a;
        }
        BigInteger ans = extGcd(b, a.remainder(b));
        BigInteger tmp = y;
        y = x;
        x = tmp;
        y = y.subtract(a.divide(b).multiply(x));
        return ans;
    }
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz