import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            BigInteger A = new BigInteger(scanner.next());
            BigInteger B = new BigInteger(scanner.next());
            BigInteger C = new BigInteger(scanner.next());
            BigInteger D = new BigInteger(scanner.next());

            BigInteger A_1 = A.subtract(BigInteger.ONE);
            BigInteger CD = lcm(C, D);

            BigInteger divide_C1 = A_1.divide(C);
            BigInteger divide_D1 = A_1.divide(D);
            BigInteger divide_CD1 = A_1.divide(CD);

            BigInteger divide_C2 = B.divide(C);
            BigInteger divide_D2 = B.divide(D);
            BigInteger divide_CD2 = B.divide(CD);

            BigInteger before_A = divide_C1.add(divide_D1).subtract(divide_CD1);
            BigInteger to_B = divide_C2.add(divide_D2).subtract(divide_CD2);

            System.out.println(B.subtract(A).add(BigInteger.ONE).subtract(to_B.subtract(before_A)));
        }
    }

    private static BigInteger lcm(BigInteger c, BigInteger d) {
        return c.multiply(d).divide(gcd(c, d));
    }

    private static BigInteger gcd(BigInteger c, BigInteger d) {
        if (c.compareTo(d) < 0) {
            return gcd(d, c);
        }
        if (d.equals(BigInteger.ZERO)) {
            return c;
        }
        return gcd(d, c.divideAndRemainder(d)[1]);
    }

} import java.math.BigInteger; BigInteger java.math import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            BigInteger A = new BigInteger(scanner.next());
            BigInteger B = new BigInteger(scanner.next());
            BigInteger C = new BigInteger(scanner.next());
            BigInteger D = new BigInteger(scanner.next());

            BigInteger A_1 = A.subtract(BigInteger.ONE);
            BigInteger CD = lcm(C, D);

            BigInteger divide_C1 = A_1.divide(C);
            BigInteger divide_D1 = A_1.divide(D);
            BigInteger divide_CD1 = A_1.divide(CD);

            BigInteger divide_C2 = B.divide(C);
            BigInteger divide_D2 = B.divide(D);
            BigInteger divide_CD2 = B.divide(CD);

            BigInteger before_A = divide_C1.add(divide_D1).subtract(divide_CD1);
            BigInteger to_B = divide_C2.add(divide_D2).subtract(divide_CD2);

            System.out.println(B.subtract(A).add(BigInteger.ONE).subtract(to_B.subtract(before_A)));
        }
    }

    private static BigInteger lcm(BigInteger c, BigInteger d) {
        return c.multiply(d).divide(gcd(c, d));
    }

    private static BigInteger gcd(BigInteger c, BigInteger d) {
        if (c.compareTo(d) < 0) {
            return gcd(d, c);
        }
        if (d.equals(BigInteger.ZERO)) {
            return c;
        }
        return gcd(d, c.divideAndRemainder(d)[1]);
    }

} Main public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            BigInteger A = new BigInteger(scanner.next());
            BigInteger B = new BigInteger(scanner.next());
            BigInteger C = new BigInteger(scanner.next());
            BigInteger D = new BigInteger(scanner.next());

            BigInteger A_1 = A.subtract(BigInteger.ONE);
            BigInteger CD = lcm(C, D);

            BigInteger divide_C1 = A_1.divide(C);
            BigInteger divide_D1 = A_1.divide(D);
            BigInteger divide_CD1 = A_1.divide(CD);

            BigInteger divide_C2 = B.divide(C);
            BigInteger divide_D2 = B.divide(D);
            BigInteger divide_CD2 = B.divide(CD);

            BigInteger before_A = divide_C1.add(divide_D1).subtract(divide_CD1);
            BigInteger to_B = divide_C2.add(divide_D2).subtract(divide_CD2);

            System.out.println(B.subtract(A).add(BigInteger.ONE).subtract(to_B.subtract(before_A)));
        }
    } main {
        try (Scanner scanner = new Scanner(System.in)) {
            BigInteger A = new BigInteger(scanner.next());
            BigInteger B = new BigInteger(scanner.next());
            BigInteger C = new BigInteger(scanner.next());
            BigInteger D = new BigInteger(scanner.next());

            BigInteger A_1 = A.subtract(BigInteger.ONE);
            BigInteger CD = lcm(C, D);

            BigInteger divide_C1 = A_1.divide(C);
            BigInteger divide_D1 = A_1.divide(D);
            BigInteger divide_CD1 = A_1.divide(CD);

            BigInteger divide_C2 = B.divide(C);
            BigInteger divide_D2 = B.divide(D);
            BigInteger divide_CD2 = B.divide(CD);

            BigInteger before_A = divide_C1.add(divide_D1).subtract(divide_CD1);
            BigInteger to_B = divide_C2.add(divide_D2).subtract(divide_CD2);

            System.out.println(B.subtract(A).add(BigInteger.ONE).subtract(to_B.subtract(before_A)));
        }
    } try (Scanner scanner = new Scanner(System.in)) {
            BigInteger A = new BigInteger(scanner.next());
            BigInteger B = new BigInteger(scanner.next());
            BigInteger C = new BigInteger(scanner.next());
            BigInteger D = new BigInteger(scanner.next());

            BigInteger A_1 = A.subtract(BigInteger.ONE);
            BigInteger CD = lcm(C, D);

            BigInteger divide_C1 = A_1.divide(C);
            BigInteger divide_D1 = A_1.divide(D);
            BigInteger divide_CD1 = A_1.divide(CD);

            BigInteger divide_C2 = B.divide(C);
            BigInteger divide_D2 = B.divide(D);
            BigInteger divide_CD2 = B.divide(CD);

            BigInteger before_A = divide_C1.add(divide_D1).subtract(divide_CD1);
            BigInteger to_B = divide_C2.add(divide_D2).subtract(divide_CD2);

            System.out.println(B.subtract(A).add(BigInteger.ONE).subtract(to_B.subtract(before_A)));
        } {
            BigInteger A = new BigInteger(scanner.next());
            BigInteger B = new BigInteger(scanner.next());
            BigInteger C = new BigInteger(scanner.next());
            BigInteger D = new BigInteger(scanner.next());

            BigInteger A_1 = A.subtract(BigInteger.ONE);
            BigInteger CD = lcm(C, D);

            BigInteger divide_C1 = A_1.divide(C);
            BigInteger divide_D1 = A_1.divide(D);
            BigInteger divide_CD1 = A_1.divide(CD);

            BigInteger divide_C2 = B.divide(C);
            BigInteger divide_D2 = B.divide(D);
            BigInteger divide_CD2 = B.divide(CD);

            BigInteger before_A = divide_C1.add(divide_D1).subtract(divide_CD1);
            BigInteger to_B = divide_C2.add(divide_D2).subtract(divide_CD2);

            System.out.println(B.subtract(A).add(BigInteger.ONE).subtract(to_B.subtract(before_A)));
        } Scanner scanner = new Scanner(System.in) Scanner scanner = new Scanner(System.in) new Scanner(System.in) BigInteger A = new BigInteger(scanner.next()); A new BigInteger(scanner.next()) BigInteger B = new BigInteger(scanner.next()); B new BigInteger(scanner.next()) BigInteger C = new BigInteger(scanner.next()); C new BigInteger(scanner.next()) BigInteger D = new BigInteger(scanner.next()); D new BigInteger(scanner.next()) BigInteger A_1 = A.subtract(BigInteger.ONE); A_1 A.subtract(BigInteger.ONE) A.subtract A BigInteger.ONE BigInteger BigInteger.ONE BigInteger CD = lcm(C, D); CD lcm(C, D) lcm C D BigInteger divide_C1 = A_1.divide(C); divide_C1 A_1.divide(C) A_1.divide A_1 C BigInteger divide_D1 = A_1.divide(D); divide_D1 A_1.divide(D) A_1.divide A_1 D BigInteger divide_CD1 = A_1.divide(CD); divide_CD1 A_1.divide(CD) A_1.divide A_1 CD BigInteger divide_C2 = B.divide(C); divide_C2 B.divide(C) B.divide B C BigInteger divide_D2 = B.divide(D); divide_D2 B.divide(D) B.divide B D BigInteger divide_CD2 = B.divide(CD); divide_CD2 B.divide(CD) B.divide B CD BigInteger before_A = divide_C1.add(divide_D1).subtract(divide_CD1); before_A divide_C1.add(divide_D1).subtract(divide_CD1) divide_C1.add(divide_D1).subtract divide_C1.add(divide_D1) divide_C1.add divide_C1 divide_D1 divide_CD1 BigInteger to_B = divide_C2.add(divide_D2).subtract(divide_CD2); to_B divide_C2.add(divide_D2).subtract(divide_CD2) divide_C2.add(divide_D2).subtract divide_C2.add(divide_D2) divide_C2.add divide_C2 divide_D2 divide_CD2 System.out.println(B.subtract(A).add(BigInteger.ONE).subtract(to_B.subtract(before_A))) System.out.println System.out System System.out B.subtract(A).add(BigInteger.ONE).subtract(to_B.subtract(before_A)) 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 to_B.subtract(before_A) to_B.subtract to_B before_A String[] args args private static BigInteger lcm(BigInteger c, BigInteger d) {
        return c.multiply(d).divide(gcd(c, d));
    } lcm {
        return c.multiply(d).divide(gcd(c, d));
    } return c.multiply(d).divide(gcd(c, d)); c.multiply(d).divide(gcd(c, d)) c.multiply(d).divide c.multiply(d) c.multiply c d gcd(c, d) gcd c d BigInteger c c BigInteger d d private static BigInteger gcd(BigInteger c, BigInteger d) {
        if (c.compareTo(d) < 0) {
            return gcd(d, c);
        }
        if (d.equals(BigInteger.ZERO)) {
            return c;
        }
        return gcd(d, c.divideAndRemainder(d)[1]);
    } gcd {
        if (c.compareTo(d) < 0) {
            return gcd(d, c);
        }
        if (d.equals(BigInteger.ZERO)) {
            return c;
        }
        return gcd(d, c.divideAndRemainder(d)[1]);
    } if (c.compareTo(d) < 0) {
            return gcd(d, c);
        } c.compareTo(d) < 0 c.compareTo(d) c.compareTo c d 0 {
            return gcd(d, c);
        } return gcd(d, c); gcd(d, c) gcd d c if (d.equals(BigInteger.ZERO)) {
            return c;
        } d.equals(BigInteger.ZERO) d.equals d BigInteger.ZERO BigInteger BigInteger.ZERO {
            return c;
        } return c; c return gcd(d, c.divideAndRemainder(d)[1]); gcd(d, c.divideAndRemainder(d)[1]) gcd d c.divideAndRemainder(d)[1] c.divideAndRemainder(d) c.divideAndRemainder c d 1 BigInteger c c BigInteger d d public class Main {

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            BigInteger A = new BigInteger(scanner.next());
            BigInteger B = new BigInteger(scanner.next());
            BigInteger C = new BigInteger(scanner.next());
            BigInteger D = new BigInteger(scanner.next());

            BigInteger A_1 = A.subtract(BigInteger.ONE);
            BigInteger CD = lcm(C, D);

            BigInteger divide_C1 = A_1.divide(C);
            BigInteger divide_D1 = A_1.divide(D);
            BigInteger divide_CD1 = A_1.divide(CD);

            BigInteger divide_C2 = B.divide(C);
            BigInteger divide_D2 = B.divide(D);
            BigInteger divide_CD2 = B.divide(CD);

            BigInteger before_A = divide_C1.add(divide_D1).subtract(divide_CD1);
            BigInteger to_B = divide_C2.add(divide_D2).subtract(divide_CD2);

            System.out.println(B.subtract(A).add(BigInteger.ONE).subtract(to_B.subtract(before_A)));
        }
    }

    private static BigInteger lcm(BigInteger c, BigInteger d) {
        return c.multiply(d).divide(gcd(c, d));
    }

    private static BigInteger gcd(BigInteger c, BigInteger d) {
        if (c.compareTo(d) < 0) {
            return gcd(d, c);
        }
        if (d.equals(BigInteger.ZERO)) {
            return c;
        }
        return gcd(d, c.divideAndRemainder(d)[1]);
    }

} public class Main {

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            BigInteger A = new BigInteger(scanner.next());
            BigInteger B = new BigInteger(scanner.next());
            BigInteger C = new BigInteger(scanner.next());
            BigInteger D = new BigInteger(scanner.next());

            BigInteger A_1 = A.subtract(BigInteger.ONE);
            BigInteger CD = lcm(C, D);

            BigInteger divide_C1 = A_1.divide(C);
            BigInteger divide_D1 = A_1.divide(D);
            BigInteger divide_CD1 = A_1.divide(CD);

            BigInteger divide_C2 = B.divide(C);
            BigInteger divide_D2 = B.divide(D);
            BigInteger divide_CD2 = B.divide(CD);

            BigInteger before_A = divide_C1.add(divide_D1).subtract(divide_CD1);
            BigInteger to_B = divide_C2.add(divide_D2).subtract(divide_CD2);

            System.out.println(B.subtract(A).add(BigInteger.ONE).subtract(to_B.subtract(before_A)));
        }
    }

    private static BigInteger lcm(BigInteger c, BigInteger d) {
        return c.multiply(d).divide(gcd(c, d));
    }

    private static BigInteger gcd(BigInteger c, BigInteger d) {
        if (c.compareTo(d) < 0) {
            return gcd(d, c);
        }
        if (d.equals(BigInteger.ZERO)) {
            return c;
        }
        return gcd(d, c.divideAndRemainder(d)[1]);
    }

} Main
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            BigInteger A = new BigInteger(scanner.next());
            BigInteger B = new BigInteger(scanner.next());
            BigInteger C = new BigInteger(scanner.next());
            BigInteger D = new BigInteger(scanner.next());

            BigInteger A_1 = A.subtract(BigInteger.ONE);
            BigInteger CD = lcm(C, D);

            BigInteger divide_C1 = A_1.divide(C);
            BigInteger divide_D1 = A_1.divide(D);
            BigInteger divide_CD1 = A_1.divide(CD);

            BigInteger divide_C2 = B.divide(C);
            BigInteger divide_D2 = B.divide(D);
            BigInteger divide_CD2 = B.divide(CD);

            BigInteger before_A = divide_C1.add(divide_D1).subtract(divide_CD1);
            BigInteger to_B = divide_C2.add(divide_D2).subtract(divide_CD2);

            System.out.println(B.subtract(A).add(BigInteger.ONE).subtract(to_B.subtract(before_A)));
        }
    }

    private static BigInteger lcm(BigInteger c, BigInteger d) {
        return c.multiply(d).divide(gcd(c, d));
    }

    private static BigInteger gcd(BigInteger c, BigInteger d) {
        if (c.compareTo(d) < 0) {
            return gcd(d, c);
        }
        if (d.equals(BigInteger.ZERO)) {
            return c;
        }
        return gcd(d, c.divideAndRemainder(d)[1]);
    }

}
