import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long A = sc.nextLong();
        long B = sc.nextLong();
        int C = sc.nextInt();
        int D = sc.nextInt();

        System.out.println(solve(A, B, C, D));

        sc.close();
    }

    static long solve(long A, long B, int C, int D) {
        return B - A + 1 - computeMultipleNum(A, B, C) - computeMultipleNum(A, B, D)
                + computeMultipleNum(A, B, lcm(C, D));
    }

    static long lcm(int x, int y) {
        return (long) x * y / gcd(x, y);
    }

    static int gcd(int x, int y) {
        return (y == 0) ? x : gcd(y, x % y);
    }

    static long computeMultipleNum(long A, long B, long factor) {
        long min = (A + factor - 1) / factor;
        long max = B / factor;

        return max - min + 1;
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long A = sc.nextLong();
        long B = sc.nextLong();
        int C = sc.nextInt();
        int D = sc.nextInt();

        System.out.println(solve(A, B, C, D));

        sc.close();
    }

    static long solve(long A, long B, int C, int D) {
        return B - A + 1 - computeMultipleNum(A, B, C) - computeMultipleNum(A, B, D)
                + computeMultipleNum(A, B, lcm(C, D));
    }

    static long lcm(int x, int y) {
        return (long) x * y / gcd(x, y);
    }

    static int gcd(int x, int y) {
        return (y == 0) ? x : gcd(y, x % y);
    }

    static long computeMultipleNum(long A, long B, long factor) {
        long min = (A + factor - 1) / factor;
        long max = B / factor;

        return max - min + 1;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long A = sc.nextLong();
        long B = sc.nextLong();
        int C = sc.nextInt();
        int D = sc.nextInt();

        System.out.println(solve(A, B, C, D));

        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);

        long A = sc.nextLong();
        long B = sc.nextLong();
        int C = sc.nextInt();
        int D = sc.nextInt();

        System.out.println(solve(A, B, C, D));

        sc.close();
    } 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 int C = sc.nextInt(); C sc.nextInt() sc.nextInt sc int D = sc.nextInt(); D sc.nextInt() sc.nextInt sc System.out.println(solve(A, B, C, D)) System.out.println System.out System System.out solve(A, B, C, D) solve A B C D sc.close() sc.close sc String[] args args static long solve(long A, long B, int C, int D) {
        return B - A + 1 - computeMultipleNum(A, B, C) - computeMultipleNum(A, B, D)
                + computeMultipleNum(A, B, lcm(C, D));
    } solve {
        return B - A + 1 - computeMultipleNum(A, B, C) - computeMultipleNum(A, B, D)
                + computeMultipleNum(A, B, lcm(C, D));
    } return B - A + 1 - computeMultipleNum(A, B, C) - computeMultipleNum(A, B, D)
                + computeMultipleNum(A, B, lcm(C, D)); B - A + 1 - computeMultipleNum(A, B, C) - computeMultipleNum(A, B, D)
                + computeMultipleNum(A, B, lcm(C, D)) B - A + 1 - computeMultipleNum(A, B, C) - computeMultipleNum(A, B, D) B - A + 1 - computeMultipleNum(A, B, C) - computeMultipleNum(A, B, D) B - A + 1 B - A B A 1 computeMultipleNum(A, B, C) computeMultipleNum A B C computeMultipleNum(A, B, D) computeMultipleNum A B D computeMultipleNum(A, B, lcm(C, D)) computeMultipleNum A B lcm(C, D) lcm C D long A A long B B int C C int D D static long lcm(int x, int y) {
        return (long) x * y / gcd(x, y);
    } lcm {
        return (long) x * y / gcd(x, y);
    } return (long) x * y / gcd(x, y); (long) x * y / gcd(x, y) (long) x * y (long) x y gcd(x, y) gcd x y int x x int y y static int gcd(int x, int y) {
        return (y == 0) ? x : gcd(y, x % y);
    } gcd {
        return (y == 0) ? x : gcd(y, x % y);
    } return (y == 0) ? x : gcd(y, x % y); (y == 0) ? x : gcd(y, x % y) (y == 0) y 0 x gcd(y, x % y) gcd y x % y x y int x x int y y static long computeMultipleNum(long A, long B, long factor) {
        long min = (A + factor - 1) / factor;
        long max = B / factor;

        return max - min + 1;
    } computeMultipleNum {
        long min = (A + factor - 1) / factor;
        long max = B / factor;

        return max - min + 1;
    } long min = (A + factor - 1) / factor; min (A + factor - 1) / factor (A + factor - 1) A + factor A factor 1 factor long max = B / factor; max B / factor B factor return max - min + 1; max - min + 1 max - min max min 1 long A A long B B long factor factor public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long A = sc.nextLong();
        long B = sc.nextLong();
        int C = sc.nextInt();
        int D = sc.nextInt();

        System.out.println(solve(A, B, C, D));

        sc.close();
    }

    static long solve(long A, long B, int C, int D) {
        return B - A + 1 - computeMultipleNum(A, B, C) - computeMultipleNum(A, B, D)
                + computeMultipleNum(A, B, lcm(C, D));
    }

    static long lcm(int x, int y) {
        return (long) x * y / gcd(x, y);
    }

    static int gcd(int x, int y) {
        return (y == 0) ? x : gcd(y, x % y);
    }

    static long computeMultipleNum(long A, long B, long factor) {
        long min = (A + factor - 1) / factor;
        long max = B / factor;

        return max - min + 1;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long A = sc.nextLong();
        long B = sc.nextLong();
        int C = sc.nextInt();
        int D = sc.nextInt();

        System.out.println(solve(A, B, C, D));

        sc.close();
    }

    static long solve(long A, long B, int C, int D) {
        return B - A + 1 - computeMultipleNum(A, B, C) - computeMultipleNum(A, B, D)
                + computeMultipleNum(A, B, lcm(C, D));
    }

    static long lcm(int x, int y) {
        return (long) x * y / gcd(x, y);
    }

    static int gcd(int x, int y) {
        return (y == 0) ? x : gcd(y, x % y);
    }

    static long computeMultipleNum(long A, long B, long factor) {
        long min = (A + factor - 1) / factor;
        long max = B / factor;

        return max - min + 1;
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long A = sc.nextLong();
        long B = sc.nextLong();
        int C = sc.nextInt();
        int D = sc.nextInt();

        System.out.println(solve(A, B, C, D));

        sc.close();
    }

    static long solve(long A, long B, int C, int D) {
        return B - A + 1 - computeMultipleNum(A, B, C) - computeMultipleNum(A, B, D)
                + computeMultipleNum(A, B, lcm(C, D));
    }

    static long lcm(int x, int y) {
        return (long) x * y / gcd(x, y);
    }

    static int gcd(int x, int y) {
        return (y == 0) ? x : gcd(y, x % y);
    }

    static long computeMultipleNum(long A, long B, long factor) {
        long min = (A + factor - 1) / factor;
        long max = B / factor;

        return max - min + 1;
    }
}