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;
    }
} import java.math.BigInteger; BigInteger java.math import java.util.*; util.* java 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);
	}
} 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);
	} main {
		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);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) BigInteger a = new BigInteger(sc.next()); a new BigInteger(sc.next()) a = a.subtract(BigInteger.ONE) a a.subtract(BigInteger.ONE) a.subtract a BigInteger.ONE BigInteger BigInteger.ONE BigInteger b = new BigInteger(sc.next()); b new BigInteger(sc.next()) BigInteger c = new BigInteger(sc.next()); c new BigInteger(sc.next()) BigInteger d = new BigInteger(sc.next()); d new BigInteger(sc.next()) BigInteger ans = b.subtract(a); ans b.subtract(a) b.subtract b a BigInteger val = b.divide(c).subtract(a.divide(c)); val b.divide(c).subtract(a.divide(c)) b.divide(c).subtract b.divide(c) b.divide b c a.divide(c) a.divide a c ans = ans.subtract(val) ans ans.subtract(val) ans.subtract ans val val = b.divide(d).subtract(a.divide(d)) val b.divide(d).subtract(a.divide(d)) b.divide(d).subtract b.divide(d) b.divide b d a.divide(d) a.divide a d ans = ans.subtract(val) ans ans.subtract(val) ans.subtract ans val BigInteger divisor = c.multiply(d).divide(Divisor.gcd(c, d)); divisor c.multiply(d).divide(Divisor.gcd(c, d)) c.multiply(d).divide c.multiply(d) c.multiply c d Divisor.gcd(c, d) Divisor.gcd Divisor c d val = b.divide(divisor).subtract(a.divide(divisor)) val b.divide(divisor).subtract(a.divide(divisor)) b.divide(divisor).subtract b.divide(divisor) b.divide b divisor a.divide(divisor) a.divide a divisor ans = ans.add(val) ans ans.add(val) ans.add ans val System.out.println(ans) System.out.println System.out System System.out ans String[] args args 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;
    }
} Divisor static BigInteger x x y; y public static BigInteger gcd(BigInteger a, BigInteger b){
        if(b.equals(BigInteger.ZERO))return a;
        return gcd(b, a.remainder(b));
    } gcd {
        if(b.equals(BigInteger.ZERO))return a;
        return gcd(b, a.remainder(b));
    } if(b.equals(BigInteger.ZERO))return a; b.equals(BigInteger.ZERO) b.equals b BigInteger.ZERO BigInteger BigInteger.ZERO return a; a return gcd(b, a.remainder(b)); gcd(b, a.remainder(b)) gcd b a.remainder(b) a.remainder a b BigInteger a a BigInteger b b 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;
    } extGcd {
        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;
    } if(b.equals(BigInteger.ZERO)){
            x = BigInteger.ONE;
            y = BigInteger.ZERO;
            return a;
        } b.equals(BigInteger.ZERO) b.equals b BigInteger.ZERO BigInteger BigInteger.ZERO {
            x = BigInteger.ONE;
            y = BigInteger.ZERO;
            return a;
        } x = BigInteger.ONE x BigInteger.ONE BigInteger BigInteger.ONE y = BigInteger.ZERO y BigInteger.ZERO BigInteger BigInteger.ZERO return a; a BigInteger ans = extGcd(b, a.remainder(b)); ans extGcd(b, a.remainder(b)) extGcd b a.remainder(b) a.remainder a b BigInteger tmp = y; tmp y y = x y x x = tmp x tmp y = y.subtract(a.divide(b).multiply(x)) y y.subtract(a.divide(b).multiply(x)) y.subtract y a.divide(b).multiply(x) a.divide(b).multiply a.divide(b) a.divide a b x return ans; ans BigInteger a a BigInteger b b
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;
    }
}