import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class CAntiDivision {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a, b, c, d;
            a = in.nextLong();
            b = in.nextLong();
            c = in.nextLong();
            d = in.nextLong();
            long x = b / c - (a - 1) / c;
            long y = b / d - (a - 1) / d;
            long e = gcd(c, d);
            long k = b - a + 1;
            e = (c * d) / e;
            long h = b / e - (a - 1) / e;
            out.println(b - a + 1 - x - y + h);
        }

        private long gcd(long c, long d) {
            if (d == 0) return c;
            else return gcd(d, c % d);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}
 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.StringTokenizer; StringTokenizer java.util import java.io.IOException; IOException java.io import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.InputStream; InputStream java.io public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CAntiDivision solver = new CAntiDivision();
        solver.solve(1, in, out);
        out.close();
    }

    static class CAntiDivision {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a, b, c, d;
            a = in.nextLong();
            b = in.nextLong();
            c = in.nextLong();
            d = in.nextLong();
            long x = b / c - (a - 1) / c;
            long y = b / d - (a - 1) / d;
            long e = gcd(c, d);
            long k = b - a + 1;
            e = (c * d) / e;
            long h = b / e - (a - 1) / e;
            out.println(b - a + 1 - x - y + h);
        }

        private long gcd(long c, long d) {
            if (d == 0) return c;
            else return gcd(d, c % d);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CAntiDivision solver = new CAntiDivision();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CAntiDivision solver = new CAntiDivision();
        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 InputReader in = new InputReader(inputStream); in new InputReader(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) CAntiDivision solver = new CAntiDivision(); solver new CAntiDivision() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class CAntiDivision {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a, b, c, d;
            a = in.nextLong();
            b = in.nextLong();
            c = in.nextLong();
            d = in.nextLong();
            long x = b / c - (a - 1) / c;
            long y = b / d - (a - 1) / d;
            long e = gcd(c, d);
            long k = b - a + 1;
            e = (c * d) / e;
            long h = b / e - (a - 1) / e;
            out.println(b - a + 1 - x - y + h);
        }

        private long gcd(long c, long d) {
            if (d == 0) return c;
            else return gcd(d, c % d);
        }

    } CAntiDivision public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a, b, c, d;
            a = in.nextLong();
            b = in.nextLong();
            c = in.nextLong();
            d = in.nextLong();
            long x = b / c - (a - 1) / c;
            long y = b / d - (a - 1) / d;
            long e = gcd(c, d);
            long k = b - a + 1;
            e = (c * d) / e;
            long h = b / e - (a - 1) / e;
            out.println(b - a + 1 - x - y + h);
        } solve {
            long a, b, c, d;
            a = in.nextLong();
            b = in.nextLong();
            c = in.nextLong();
            d = in.nextLong();
            long x = b / c - (a - 1) / c;
            long y = b / d - (a - 1) / d;
            long e = gcd(c, d);
            long k = b - a + 1;
            e = (c * d) / e;
            long h = b / e - (a - 1) / e;
            out.println(b - a + 1 - x - y + h);
        } long a a b b c c d; d a = in.nextLong() a in.nextLong() in.nextLong in b = in.nextLong() b in.nextLong() in.nextLong in c = in.nextLong() c in.nextLong() in.nextLong in d = in.nextLong() d in.nextLong() in.nextLong in long x = b / c - (a - 1) / c; x b / c - (a - 1) / c b / c b c (a - 1) / c (a - 1) a 1 c long y = b / d - (a - 1) / d; y b / d - (a - 1) / d b / d b d (a - 1) / d (a - 1) a 1 d long e = gcd(c, d); e gcd(c, d) gcd c d long k = b - a + 1; k b - a + 1 b - a b a 1 e = (c * d) / e e (c * d) / e (c * d) c d e long h = b / e - (a - 1) / e; h b / e - (a - 1) / e b / e b e (a - 1) / e (a - 1) a 1 e out.println(b - a + 1 - x - y + h) out.println out b - a + 1 - x - y + h b - a + 1 - x - y b - a + 1 - x - y b - a + 1 b - a b a 1 x y h int testNumber testNumber InputReader in in PrintWriter out out private long gcd(long c, long d) {
            if (d == 0) return c;
            else return gcd(d, c % d);
        } gcd {
            if (d == 0) return c;
            else return gcd(d, c % d);
        } if (d == 0) return c;
            else return gcd(d, c % d); d == 0 d 0 return c; c return gcd(d, c % d); gcd(d, c % d) gcd d c % d c d long c c long d d static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    } InputReader public BufferedReader reader; reader public StringTokenizer tokenizer; tokenizer public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        } InputReader {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        } reader = new BufferedReader(new InputStreamReader(stream), 32768) reader new BufferedReader(new InputStreamReader(stream), 32768) tokenizer = null tokenizer null InputStream stream stream public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } next {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        } while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } tokenizer == null || !tokenizer.hasMoreTokens() tokenizer == null tokenizer null !tokenizer.hasMoreTokens() tokenizer.hasMoreTokens() tokenizer.hasMoreTokens tokenizer {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            } try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } IOException e {
                    throw new RuntimeException(e);
                } throw new RuntimeException(e); new RuntimeException(e) {
                    tokenizer = new StringTokenizer(reader.readLine());
                } tokenizer = new StringTokenizer(reader.readLine()) tokenizer new StringTokenizer(reader.readLine()) return tokenizer.nextToken(); tokenizer.nextToken() tokenizer.nextToken tokenizer public long nextLong() {
            return Long.parseLong(next());
        } nextLong {
            return Long.parseLong(next());
        } return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CAntiDivision solver = new CAntiDivision();
        solver.solve(1, in, out);
        out.close();
    }

    static class CAntiDivision {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a, b, c, d;
            a = in.nextLong();
            b = in.nextLong();
            c = in.nextLong();
            d = in.nextLong();
            long x = b / c - (a - 1) / c;
            long y = b / d - (a - 1) / d;
            long e = gcd(c, d);
            long k = b - a + 1;
            e = (c * d) / e;
            long h = b / e - (a - 1) / e;
            out.println(b - a + 1 - x - y + h);
        }

        private long gcd(long c, long d) {
            if (d == 0) return c;
            else return gcd(d, c % d);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

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

    static class CAntiDivision {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a, b, c, d;
            a = in.nextLong();
            b = in.nextLong();
            c = in.nextLong();
            d = in.nextLong();
            long x = b / c - (a - 1) / c;
            long y = b / d - (a - 1) / d;
            long e = gcd(c, d);
            long k = b - a + 1;
            e = (c * d) / e;
            long h = b / e - (a - 1) / e;
            out.println(b - a + 1 - x - y + h);
        }

        private long gcd(long c, long d) {
            if (d == 0) return c;
            else return gcd(d, c % d);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class CAntiDivision {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a, b, c, d;
            a = in.nextLong();
            b = in.nextLong();
            c = in.nextLong();
            d = in.nextLong();
            long x = b / c - (a - 1) / c;
            long y = b / d - (a - 1) / d;
            long e = gcd(c, d);
            long k = b - a + 1;
            e = (c * d) / e;
            long h = b / e - (a - 1) / e;
            out.println(b - a + 1 - x - y + h);
        }

        private long gcd(long c, long d) {
            if (d == 0) return c;
            else return gcd(d, c % d);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

