import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            long[] a = readLongArray(reader);
            long A = a[0];
            long B = a[1];
            long C = a[2];
            long D = a[3];

            long lcm = lcm(C, D);

            long x = (B - B / C) - (A - 1 - (A - 1) / C);
            long y = (B - B / D) - (A - 1 - (A - 1) / D);
            long z = (B - B / lcm) - (A - 1 - (A - 1) / lcm);

            System.out.println(x + y - z);
        }
    }

    public static long gcd(long M, long N) {
        long a;

        if (M < N) {
            a = N;
            N = M;
            M = a;
        }

        while (M % N != 0) {
            a = N;
            N = M % N;
            M = a;
        }

        return N;
    }

    public static long lcm(long M, long N) {
        return M * N / gcd(M, N);
    }

    public static long[] readLongArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    }

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            long[] a = readLongArray(reader);
            long A = a[0];
            long B = a[1];
            long C = a[2];
            long D = a[3];

            long lcm = lcm(C, D);

            long x = (B - B / C) - (A - 1 - (A - 1) / C);
            long y = (B - B / D) - (A - 1 - (A - 1) / D);
            long z = (B - B / lcm) - (A - 1 - (A - 1) / lcm);

            System.out.println(x + y - z);
        }
    }

    public static long gcd(long M, long N) {
        long a;

        if (M < N) {
            a = N;
            N = M;
            M = a;
        }

        while (M % N != 0) {
            a = N;
            N = M % N;
            M = a;
        }

        return N;
    }

    public static long lcm(long M, long N) {
        return M * N / gcd(M, N);
    }

    public static long[] readLongArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    }

} Main public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            long[] a = readLongArray(reader);
            long A = a[0];
            long B = a[1];
            long C = a[2];
            long D = a[3];

            long lcm = lcm(C, D);

            long x = (B - B / C) - (A - 1 - (A - 1) / C);
            long y = (B - B / D) - (A - 1 - (A - 1) / D);
            long z = (B - B / lcm) - (A - 1 - (A - 1) / lcm);

            System.out.println(x + y - z);
        }
    } main {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            long[] a = readLongArray(reader);
            long A = a[0];
            long B = a[1];
            long C = a[2];
            long D = a[3];

            long lcm = lcm(C, D);

            long x = (B - B / C) - (A - 1 - (A - 1) / C);
            long y = (B - B / D) - (A - 1 - (A - 1) / D);
            long z = (B - B / lcm) - (A - 1 - (A - 1) / lcm);

            System.out.println(x + y - z);
        }
    } try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            long[] a = readLongArray(reader);
            long A = a[0];
            long B = a[1];
            long C = a[2];
            long D = a[3];

            long lcm = lcm(C, D);

            long x = (B - B / C) - (A - 1 - (A - 1) / C);
            long y = (B - B / D) - (A - 1 - (A - 1) / D);
            long z = (B - B / lcm) - (A - 1 - (A - 1) / lcm);

            System.out.println(x + y - z);
        } {
            long[] a = readLongArray(reader);
            long A = a[0];
            long B = a[1];
            long C = a[2];
            long D = a[3];

            long lcm = lcm(C, D);

            long x = (B - B / C) - (A - 1 - (A - 1) / C);
            long y = (B - B / D) - (A - 1 - (A - 1) / D);
            long z = (B - B / lcm) - (A - 1 - (A - 1) / lcm);

            System.out.println(x + y - z);
        } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)) BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) long[] a = readLongArray(reader); a readLongArray(reader) readLongArray reader long A = a[0]; A a[0] a 0 long B = a[1]; B a[1] a 1 long C = a[2]; C a[2] a 2 long D = a[3]; D a[3] a 3 long lcm = lcm(C, D); lcm lcm(C, D) lcm C D long x = (B - B / C) - (A - 1 - (A - 1) / C); x (B - B / C) - (A - 1 - (A - 1) / C) (B - B / C) B B / C B C (A - 1 - (A - 1) / C) A - 1 - (A - 1) / C A 1 (A - 1) / C (A - 1) A 1 C long y = (B - B / D) - (A - 1 - (A - 1) / D); y (B - B / D) - (A - 1 - (A - 1) / D) (B - B / D) B B / D B D (A - 1 - (A - 1) / D) A - 1 - (A - 1) / D A 1 (A - 1) / D (A - 1) A 1 D long z = (B - B / lcm) - (A - 1 - (A - 1) / lcm); z (B - B / lcm) - (A - 1 - (A - 1) / lcm) (B - B / lcm) B B / lcm B lcm (A - 1 - (A - 1) / lcm) A - 1 - (A - 1) / lcm A 1 (A - 1) / lcm (A - 1) A 1 lcm System.out.println(x + y - z) System.out.println System.out System System.out x + y - z x + y x y z String[] args args public static long gcd(long M, long N) {
        long a;

        if (M < N) {
            a = N;
            N = M;
            M = a;
        }

        while (M % N != 0) {
            a = N;
            N = M % N;
            M = a;
        }

        return N;
    } gcd {
        long a;

        if (M < N) {
            a = N;
            N = M;
            M = a;
        }

        while (M % N != 0) {
            a = N;
            N = M % N;
            M = a;
        }

        return N;
    } long a; a if (M < N) {
            a = N;
            N = M;
            M = a;
        } M < N M N {
            a = N;
            N = M;
            M = a;
        } a = N a N N = M N M M = a M a while (M % N != 0) {
            a = N;
            N = M % N;
            M = a;
        } M % N != 0 M % N M N 0 {
            a = N;
            N = M % N;
            M = a;
        } a = N a N N = M % N N M % N M N M = a M a return N; N long M M long N N public static long lcm(long M, long N) {
        return M * N / gcd(M, N);
    } lcm {
        return M * N / gcd(M, N);
    } return M * N / gcd(M, N); M * N / gcd(M, N) M * N M N gcd(M, N) gcd M N long M M long N N public static long[] readLongArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    } readLongArray {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    } String[] str = reader.readLine().split(" "); str reader.readLine().split(" ") reader.readLine().split reader.readLine() reader.readLine reader " " long[] array = new long[str.length]; array new long[str.length] str.length str str.length for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        } int i = 0; int i = 0; i 0 i < str.length i str.length str str.length i++ i++ i {
            array[i] = Long.parseLong(str[i]);
        } {
            array[i] = Long.parseLong(str[i]);
        } array[i] = Long.parseLong(str[i]) array[i] array i Long.parseLong(str[i]) Long.parseLong Long str[i] str i return array; array BufferedReader reader reader public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            long[] a = readLongArray(reader);
            long A = a[0];
            long B = a[1];
            long C = a[2];
            long D = a[3];

            long lcm = lcm(C, D);

            long x = (B - B / C) - (A - 1 - (A - 1) / C);
            long y = (B - B / D) - (A - 1 - (A - 1) / D);
            long z = (B - B / lcm) - (A - 1 - (A - 1) / lcm);

            System.out.println(x + y - z);
        }
    }

    public static long gcd(long M, long N) {
        long a;

        if (M < N) {
            a = N;
            N = M;
            M = a;
        }

        while (M % N != 0) {
            a = N;
            N = M % N;
            M = a;
        }

        return N;
    }

    public static long lcm(long M, long N) {
        return M * N / gcd(M, N);
    }

    public static long[] readLongArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    }

} public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            long[] a = readLongArray(reader);
            long A = a[0];
            long B = a[1];
            long C = a[2];
            long D = a[3];

            long lcm = lcm(C, D);

            long x = (B - B / C) - (A - 1 - (A - 1) / C);
            long y = (B - B / D) - (A - 1 - (A - 1) / D);
            long z = (B - B / lcm) - (A - 1 - (A - 1) / lcm);

            System.out.println(x + y - z);
        }
    }

    public static long gcd(long M, long N) {
        long a;

        if (M < N) {
            a = N;
            N = M;
            M = a;
        }

        while (M % N != 0) {
            a = N;
            N = M % N;
            M = a;
        }

        return N;
    }

    public static long lcm(long M, long N) {
        return M * N / gcd(M, N);
    }

    public static long[] readLongArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    }

} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            long[] a = readLongArray(reader);
            long A = a[0];
            long B = a[1];
            long C = a[2];
            long D = a[3];

            long lcm = lcm(C, D);

            long x = (B - B / C) - (A - 1 - (A - 1) / C);
            long y = (B - B / D) - (A - 1 - (A - 1) / D);
            long z = (B - B / lcm) - (A - 1 - (A - 1) / lcm);

            System.out.println(x + y - z);
        }
    }

    public static long gcd(long M, long N) {
        long a;

        if (M < N) {
            a = N;
            N = M;
            M = a;
        }

        while (M % N != 0) {
            a = N;
            N = M % N;
            M = a;
        }

        return N;
    }

    public static long lcm(long M, long N) {
        return M * N / gcd(M, N);
    }

    public static long[] readLongArray(BufferedReader reader) throws Exception {
        String[] str = reader.readLine().split(" ");
        long[] array = new long[str.length];
        for (int i = 0; i < str.length; i++) {
            array[i] = Long.parseLong(str[i]);
        }
        return array;
    }

}
