import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    static final int MAX = 100100;
    InputStream in = System.in;
    PrintStream out = System.out;

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

    public BigInteger lcm(BigInteger a, BigInteger b) {
        return a.multiply(b).divide(gcd(a,b));
    }

    public BigInteger f(BigInteger a, BigInteger b, BigInteger c) {
        BigInteger n =  b.divide(c).subtract(a.subtract(BigInteger.ONE).divide(c));
        return n;
    }

    public void _main(String[] args) {
        Scanner sc = new Scanner(in);
        BigInteger A = sc.nextBigInteger(), B = sc.nextBigInteger();
        BigInteger C = sc.nextBigInteger(), D = sc.nextBigInteger();
        out.println((B.subtract(A).add(BigInteger.ONE)).subtract(f(A,B,C)).subtract(f(A,B,D)).add(f(A,B,lcm(C,D))));
    }

    public static void main(String[] args) {
        new Main()._main(args);
    }
} import java.io.InputStream; InputStream java.io import java.io.PrintStream; PrintStream java.io import java.math.BigInteger; BigInteger java.math import java.util.Scanner; Scanner java.util public class Main {
    static final int MAX = 100100;
    InputStream in = System.in;
    PrintStream out = System.out;

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

    public BigInteger lcm(BigInteger a, BigInteger b) {
        return a.multiply(b).divide(gcd(a,b));
    }

    public BigInteger f(BigInteger a, BigInteger b, BigInteger c) {
        BigInteger n =  b.divide(c).subtract(a.subtract(BigInteger.ONE).divide(c));
        return n;
    }

    public void _main(String[] args) {
        Scanner sc = new Scanner(in);
        BigInteger A = sc.nextBigInteger(), B = sc.nextBigInteger();
        BigInteger C = sc.nextBigInteger(), D = sc.nextBigInteger();
        out.println((B.subtract(A).add(BigInteger.ONE)).subtract(f(A,B,C)).subtract(f(A,B,D)).add(f(A,B,lcm(C,D))));
    }

    public static void main(String[] args) {
        new Main()._main(args);
    }
} Main static final int MAX = 100100; MAX 100100 InputStream in = System.in; in System.in System System.in PrintStream out = System.out; out System.out System System.out public 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 BigInteger lcm(BigInteger a, BigInteger b) {
        return a.multiply(b).divide(gcd(a,b));
    } lcm {
        return a.multiply(b).divide(gcd(a,b));
    } return a.multiply(b).divide(gcd(a,b)); a.multiply(b).divide(gcd(a,b)) a.multiply(b).divide a.multiply(b) a.multiply a b gcd(a,b) gcd a b BigInteger a a BigInteger b b public BigInteger f(BigInteger a, BigInteger b, BigInteger c) {
        BigInteger n =  b.divide(c).subtract(a.subtract(BigInteger.ONE).divide(c));
        return n;
    } f {
        BigInteger n =  b.divide(c).subtract(a.subtract(BigInteger.ONE).divide(c));
        return n;
    } BigInteger n =  b.divide(c).subtract(a.subtract(BigInteger.ONE).divide(c)); n b.divide(c).subtract(a.subtract(BigInteger.ONE).divide(c)) b.divide(c).subtract b.divide(c) b.divide b c a.subtract(BigInteger.ONE).divide(c) a.subtract(BigInteger.ONE).divide a.subtract(BigInteger.ONE) a.subtract a BigInteger.ONE BigInteger BigInteger.ONE c return n; n BigInteger a a BigInteger b b BigInteger c c public void _main(String[] args) {
        Scanner sc = new Scanner(in);
        BigInteger A = sc.nextBigInteger(), B = sc.nextBigInteger();
        BigInteger C = sc.nextBigInteger(), D = sc.nextBigInteger();
        out.println((B.subtract(A).add(BigInteger.ONE)).subtract(f(A,B,C)).subtract(f(A,B,D)).add(f(A,B,lcm(C,D))));
    } _main {
        Scanner sc = new Scanner(in);
        BigInteger A = sc.nextBigInteger(), B = sc.nextBigInteger();
        BigInteger C = sc.nextBigInteger(), D = sc.nextBigInteger();
        out.println((B.subtract(A).add(BigInteger.ONE)).subtract(f(A,B,C)).subtract(f(A,B,D)).add(f(A,B,lcm(C,D))));
    } Scanner sc = new Scanner(in); sc new Scanner(in) BigInteger A = sc.nextBigInteger() A sc.nextBigInteger() sc.nextBigInteger sc B = sc.nextBigInteger(); B sc.nextBigInteger() sc.nextBigInteger sc BigInteger C = sc.nextBigInteger() C sc.nextBigInteger() sc.nextBigInteger sc D = sc.nextBigInteger(); D sc.nextBigInteger() sc.nextBigInteger sc out.println((B.subtract(A).add(BigInteger.ONE)).subtract(f(A,B,C)).subtract(f(A,B,D)).add(f(A,B,lcm(C,D)))) out.println out (B.subtract(A).add(BigInteger.ONE)).subtract(f(A,B,C)).subtract(f(A,B,D)).add(f(A,B,lcm(C,D))) (B.subtract(A).add(BigInteger.ONE)).subtract(f(A,B,C)).subtract(f(A,B,D)).add (B.subtract(A).add(BigInteger.ONE)).subtract(f(A,B,C)).subtract(f(A,B,D)) (B.subtract(A).add(BigInteger.ONE)).subtract(f(A,B,C)).subtract (B.subtract(A).add(BigInteger.ONE)).subtract(f(A,B,C)) (B.subtract(A).add(BigInteger.ONE)).subtract (B.subtract(A).add(BigInteger.ONE)) B.subtract(A).add B.subtract(A) B.subtract B A BigInteger.ONE BigInteger BigInteger.ONE f(A,B,C) f A B C f(A,B,D) f A B D f(A,B,lcm(C,D)) f A B lcm(C,D) lcm C D String[] args args public static void main(String[] args) {
        new Main()._main(args);
    } main {
        new Main()._main(args);
    } new Main()._main(args) new Main()._main new Main() args String[] args args public class Main {
    static final int MAX = 100100;
    InputStream in = System.in;
    PrintStream out = System.out;

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

    public BigInteger lcm(BigInteger a, BigInteger b) {
        return a.multiply(b).divide(gcd(a,b));
    }

    public BigInteger f(BigInteger a, BigInteger b, BigInteger c) {
        BigInteger n =  b.divide(c).subtract(a.subtract(BigInteger.ONE).divide(c));
        return n;
    }

    public void _main(String[] args) {
        Scanner sc = new Scanner(in);
        BigInteger A = sc.nextBigInteger(), B = sc.nextBigInteger();
        BigInteger C = sc.nextBigInteger(), D = sc.nextBigInteger();
        out.println((B.subtract(A).add(BigInteger.ONE)).subtract(f(A,B,C)).subtract(f(A,B,D)).add(f(A,B,lcm(C,D))));
    }

    public static void main(String[] args) {
        new Main()._main(args);
    }
} public class Main {
    static final int MAX = 100100;
    InputStream in = System.in;
    PrintStream out = System.out;

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

    public BigInteger lcm(BigInteger a, BigInteger b) {
        return a.multiply(b).divide(gcd(a,b));
    }

    public BigInteger f(BigInteger a, BigInteger b, BigInteger c) {
        BigInteger n =  b.divide(c).subtract(a.subtract(BigInteger.ONE).divide(c));
        return n;
    }

    public void _main(String[] args) {
        Scanner sc = new Scanner(in);
        BigInteger A = sc.nextBigInteger(), B = sc.nextBigInteger();
        BigInteger C = sc.nextBigInteger(), D = sc.nextBigInteger();
        out.println((B.subtract(A).add(BigInteger.ONE)).subtract(f(A,B,C)).subtract(f(A,B,D)).add(f(A,B,lcm(C,D))));
    }

    public static void main(String[] args) {
        new Main()._main(args);
    }
} Main
import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    static final int MAX = 100100;
    InputStream in = System.in;
    PrintStream out = System.out;

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

    public BigInteger lcm(BigInteger a, BigInteger b) {
        return a.multiply(b).divide(gcd(a,b));
    }

    public BigInteger f(BigInteger a, BigInteger b, BigInteger c) {
        BigInteger n =  b.divide(c).subtract(a.subtract(BigInteger.ONE).divide(c));
        return n;
    }

    public void _main(String[] args) {
        Scanner sc = new Scanner(in);
        BigInteger A = sc.nextBigInteger(), B = sc.nextBigInteger();
        BigInteger C = sc.nextBigInteger(), D = sc.nextBigInteger();
        out.println((B.subtract(A).add(BigInteger.ONE)).subtract(f(A,B,C)).subtract(f(A,B,D)).add(f(A,B,lcm(C,D))));
    }

    public static void main(String[] args) {
        new Main()._main(args);
    }
}
