import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AntiDivision solver = new AntiDivision();
        solver.solve(1, in, out);
        out.close();
    }

    static class AntiDivision {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long c = in.nextLong();
            long d = in.nextLong();

            long cdiv = (b / c) - ((a - 1) / c);
            long ddiv = (b / d) - ((a - 1) / d);
            long cddiv = (b / lcm(c, d)) - ((a - 1) / lcm(c, d));

            out.println(b - a + 1 - cdiv - ddiv + cddiv);
        }

        static long lcm(long a, long b) {
            return a * b / gcd(a, b);
        }

        static long gcd(long a, long b) {
            return b == 0 ? a : gcd(b, a % b);
        }

    }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AntiDivision solver = new AntiDivision();
        solver.solve(1, in, out);
        out.close();
    }

    static class AntiDivision {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long c = in.nextLong();
            long d = in.nextLong();

            long cdiv = (b / c) - ((a - 1) / c);
            long ddiv = (b / d) - ((a - 1) / d);
            long cddiv = (b / lcm(c, d)) - ((a - 1) / lcm(c, d));

            out.println(b - a + 1 - cdiv - ddiv + cddiv);
        }

        static long lcm(long a, long b) {
            return a * b / gcd(a, b);
        }

        static long gcd(long a, long b) {
            return b == 0 ? a : gcd(b, a % b);
        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AntiDivision solver = new AntiDivision();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AntiDivision solver = new AntiDivision();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out Scanner in = new Scanner(inputStream); in new Scanner(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) AntiDivision solver = new AntiDivision(); solver new AntiDivision() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class AntiDivision {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long c = in.nextLong();
            long d = in.nextLong();

            long cdiv = (b / c) - ((a - 1) / c);
            long ddiv = (b / d) - ((a - 1) / d);
            long cddiv = (b / lcm(c, d)) - ((a - 1) / lcm(c, d));

            out.println(b - a + 1 - cdiv - ddiv + cddiv);
        }

        static long lcm(long a, long b) {
            return a * b / gcd(a, b);
        }

        static long gcd(long a, long b) {
            return b == 0 ? a : gcd(b, a % b);
        }

    } AntiDivision public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long c = in.nextLong();
            long d = in.nextLong();

            long cdiv = (b / c) - ((a - 1) / c);
            long ddiv = (b / d) - ((a - 1) / d);
            long cddiv = (b / lcm(c, d)) - ((a - 1) / lcm(c, d));

            out.println(b - a + 1 - cdiv - ddiv + cddiv);
        } solve {
            long a = in.nextLong();
            long b = in.nextLong();
            long c = in.nextLong();
            long d = in.nextLong();

            long cdiv = (b / c) - ((a - 1) / c);
            long ddiv = (b / d) - ((a - 1) / d);
            long cddiv = (b / lcm(c, d)) - ((a - 1) / lcm(c, d));

            out.println(b - a + 1 - cdiv - ddiv + cddiv);
        } long a = in.nextLong(); a in.nextLong() in.nextLong in long b = in.nextLong(); b in.nextLong() in.nextLong in long c = in.nextLong(); c in.nextLong() in.nextLong in long d = in.nextLong(); d in.nextLong() in.nextLong in long cdiv = (b / c) - ((a - 1) / c); cdiv (b / c) - ((a - 1) / c) (b / c) b c ((a - 1) / c) (a - 1) a 1 c long ddiv = (b / d) - ((a - 1) / d); ddiv (b / d) - ((a - 1) / d) (b / d) b d ((a - 1) / d) (a - 1) a 1 d long cddiv = (b / lcm(c, d)) - ((a - 1) / lcm(c, d)); cddiv (b / lcm(c, d)) - ((a - 1) / lcm(c, d)) (b / lcm(c, d)) b lcm(c, d) lcm c d ((a - 1) / lcm(c, d)) (a - 1) a 1 lcm(c, d) lcm c d out.println(b - a + 1 - cdiv - ddiv + cddiv) out.println out b - a + 1 - cdiv - ddiv + cddiv b - a + 1 - cdiv - ddiv b - a + 1 - cdiv - ddiv b - a + 1 b - a b a 1 cdiv ddiv cddiv int testNumber testNumber Scanner in in PrintWriter out out static long lcm(long a, long b) {
            return a * b / gcd(a, b);
        } lcm {
            return a * b / gcd(a, b);
        } return a * b / gcd(a, b); a * b / gcd(a, b) a * b a b gcd(a, b) gcd a b long a a long b b static long gcd(long a, long b) {
            return b == 0 ? a : gcd(b, a % b);
        } gcd {
            return b == 0 ? a : gcd(b, a % b);
        } return b == 0 ? a : gcd(b, a % b); b == 0 ? a : gcd(b, a % b) b == 0 b 0 a gcd(b, a % b) gcd b a % b a b long a a long b b public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AntiDivision solver = new AntiDivision();
        solver.solve(1, in, out);
        out.close();
    }

    static class AntiDivision {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long c = in.nextLong();
            long d = in.nextLong();

            long cdiv = (b / c) - ((a - 1) / c);
            long ddiv = (b / d) - ((a - 1) / d);
            long cddiv = (b / lcm(c, d)) - ((a - 1) / lcm(c, d));

            out.println(b - a + 1 - cdiv - ddiv + cddiv);
        }

        static long lcm(long a, long b) {
            return a * b / gcd(a, b);
        }

        static long gcd(long a, long b) {
            return b == 0 ? a : gcd(b, a % b);
        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AntiDivision solver = new AntiDivision();
        solver.solve(1, in, out);
        out.close();
    }

    static class AntiDivision {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long c = in.nextLong();
            long d = in.nextLong();

            long cdiv = (b / c) - ((a - 1) / c);
            long ddiv = (b / d) - ((a - 1) / d);
            long cddiv = (b / lcm(c, d)) - ((a - 1) / lcm(c, d));

            out.println(b - a + 1 - cdiv - ddiv + cddiv);
        }

        static long lcm(long a, long b) {
            return a * b / gcd(a, b);
        }

        static long gcd(long a, long b) {
            return b == 0 ? a : gcd(b, a % b);
        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AntiDivision solver = new AntiDivision();
        solver.solve(1, in, out);
        out.close();
    }

    static class AntiDivision {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long c = in.nextLong();
            long d = in.nextLong();

            long cdiv = (b / c) - ((a - 1) / c);
            long ddiv = (b / d) - ((a - 1) / d);
            long cddiv = (b / lcm(c, d)) - ((a - 1) / lcm(c, d));

            out.println(b - a + 1 - cdiv - ddiv + cddiv);
        }

        static long lcm(long a, long b) {
            return a * b / gcd(a, b);
        }

        static long gcd(long a, long b) {
            return b == 0 ? a : gcd(b, a % b);
        }

    }
}

