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);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            Long a = Long.parseLong(in.next());
            Long b = Long.parseLong(in.next());
            Long c = Long.parseLong(in.next());
            Long d = Long.parseLong(in.next());

            Long G = gcd(c, d);
            Long L = c / G * d;
            Long ans1 = b - b / c - b / d + b / L;
            Long ans2 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / L;

            // 出力
            out.println(ans1 - ans2);

        }

        public static long gcd(long num1, long num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        }

    }
}
 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);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            Long a = Long.parseLong(in.next());
            Long b = Long.parseLong(in.next());
            Long c = Long.parseLong(in.next());
            Long d = Long.parseLong(in.next());

            Long G = gcd(c, d);
            Long L = c / G * d;
            Long ans1 = b - b / c - b / d + b / L;
            Long ans2 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / L;

            // 出力
            out.println(ans1 - ans2);

        }

        public static long gcd(long num1, long num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        }

    }
} 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);
        C solver = new C();
        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);
        C solver = new C();
        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) C solver = new C(); solver new C() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            Long a = Long.parseLong(in.next());
            Long b = Long.parseLong(in.next());
            Long c = Long.parseLong(in.next());
            Long d = Long.parseLong(in.next());

            Long G = gcd(c, d);
            Long L = c / G * d;
            Long ans1 = b - b / c - b / d + b / L;
            Long ans2 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / L;

            // 出力
            out.println(ans1 - ans2);

        }

        public static long gcd(long num1, long num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        }

    } C public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            Long a = Long.parseLong(in.next());
            Long b = Long.parseLong(in.next());
            Long c = Long.parseLong(in.next());
            Long d = Long.parseLong(in.next());

            Long G = gcd(c, d);
            Long L = c / G * d;
            Long ans1 = b - b / c - b / d + b / L;
            Long ans2 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / L;

            // 出力
            out.println(ans1 - ans2);

        } solve {
            // 入力
            Long a = Long.parseLong(in.next());
            Long b = Long.parseLong(in.next());
            Long c = Long.parseLong(in.next());
            Long d = Long.parseLong(in.next());

            Long G = gcd(c, d);
            Long L = c / G * d;
            Long ans1 = b - b / c - b / d + b / L;
            Long ans2 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / L;

            // 出力
            out.println(ans1 - ans2);

        } Long a = Long.parseLong(in.next()); a Long.parseLong(in.next()) Long.parseLong Long in.next() in.next in Long b = Long.parseLong(in.next()); b Long.parseLong(in.next()) Long.parseLong Long in.next() in.next in Long c = Long.parseLong(in.next()); c Long.parseLong(in.next()) Long.parseLong Long in.next() in.next in Long d = Long.parseLong(in.next()); d Long.parseLong(in.next()) Long.parseLong Long in.next() in.next in Long G = gcd(c, d); G gcd(c, d) gcd c d Long L = c / G * d; L c / G * d c / G c G d Long ans1 = b - b / c - b / d + b / L; ans1 b - b / c - b / d + b / L b - b / c - b / d b - b / c - b / d b b / c b c b / d b d b / L b L Long ans2 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / L; ans2 (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / L (a - 1) - (a - 1) / c - (a - 1) / d (a - 1) - (a - 1) / c - (a - 1) / d (a - 1) a 1 (a - 1) / c (a - 1) a 1 c (a - 1) / d (a - 1) a 1 d (a - 1) / L (a - 1) a 1 L out.println(ans1 - ans2) out.println out ans1 - ans2 ans1 ans2 int testNumber testNumber Scanner in in PrintWriter out out public static long gcd(long num1, long num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        } gcd {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        } if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2); num2 == 0 num2 0 return num1; num1 return gcd(num2, num1 % num2); gcd(num2, num1 % num2) gcd num2 num1 % num2 num1 num2 long num1 num1 long num2 num2 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);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            Long a = Long.parseLong(in.next());
            Long b = Long.parseLong(in.next());
            Long c = Long.parseLong(in.next());
            Long d = Long.parseLong(in.next());

            Long G = gcd(c, d);
            Long L = c / G * d;
            Long ans1 = b - b / c - b / d + b / L;
            Long ans2 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / L;

            // 出力
            out.println(ans1 - ans2);

        }

        public static long gcd(long num1, long num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        }

    }
} 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);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            Long a = Long.parseLong(in.next());
            Long b = Long.parseLong(in.next());
            Long c = Long.parseLong(in.next());
            Long d = Long.parseLong(in.next());

            Long G = gcd(c, d);
            Long L = c / G * d;
            Long ans1 = b - b / c - b / d + b / L;
            Long ans2 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / L;

            // 出力
            out.println(ans1 - ans2);

        }

        public static long gcd(long num1, long num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        }

    }
} 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);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            Long a = Long.parseLong(in.next());
            Long b = Long.parseLong(in.next());
            Long c = Long.parseLong(in.next());
            Long d = Long.parseLong(in.next());

            Long G = gcd(c, d);
            Long L = c / G * d;
            Long ans1 = b - b / c - b / d + b / L;
            Long ans2 = (a - 1) - (a - 1) / c - (a - 1) / d + (a - 1) / L;

            // 出力
            out.println(ans1 - ans2);

        }

        public static long gcd(long num1, long num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        }

    }
}

