import java.util.Scanner;

public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        // 全体数 - (B以下でCまたはDで割り切れるものの個数 - A-1以下でCまたはDで割り切れるものの個数)
        long ans = (B - A + 1) -
                ((B/C + B/D - B/(C*D/gcd(C, D))) - ((A-1)/C + (A-1)/D - (A-1)/(C*D/gcd(C, D))));
    System.out.print(ans);
    }


    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
} import java.util.Scanner; Scanner java.util public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        // 全体数 - (B以下でCまたはDで割り切れるものの個数 - A-1以下でCまたはDで割り切れるものの個数)
        long ans = (B - A + 1) -
                ((B/C + B/D - B/(C*D/gcd(C, D))) - ((A-1)/C + (A-1)/D - (A-1)/(C*D/gcd(C, D))));
    System.out.print(ans);
    }


    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
} Main private void solve() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        // 全体数 - (B以下でCまたはDで割り切れるものの個数 - A-1以下でCまたはDで割り切れるものの個数)
        long ans = (B - A + 1) -
                ((B/C + B/D - B/(C*D/gcd(C, D))) - ((A-1)/C + (A-1)/D - (A-1)/(C*D/gcd(C, D))));
    System.out.print(ans);
    } solve {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        // 全体数 - (B以下でCまたはDで割り切れるものの個数 - A-1以下でCまたはDで割り切れるものの個数)
        long ans = (B - A + 1) -
                ((B/C + B/D - B/(C*D/gcd(C, D))) - ((A-1)/C + (A-1)/D - (A-1)/(C*D/gcd(C, D))));
    System.out.print(ans);
    } 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 long C = sc.nextLong(); C sc.nextLong() sc.nextLong sc long D = sc.nextLong(); D sc.nextLong() sc.nextLong sc long ans = (B - A + 1) -
                ((B/C + B/D - B/(C*D/gcd(C, D))) - ((A-1)/C + (A-1)/D - (A-1)/(C*D/gcd(C, D)))); ans (B - A + 1) -
                ((B/C + B/D - B/(C*D/gcd(C, D))) - ((A-1)/C + (A-1)/D - (A-1)/(C*D/gcd(C, D)))) (B - A + 1) B - A B A 1 ((B/C + B/D - B/(C*D/gcd(C, D))) - ((A-1)/C + (A-1)/D - (A-1)/(C*D/gcd(C, D)))) (B/C + B/D - B/(C*D/gcd(C, D))) B/C + B/D B/C B C B/D B D B/(C*D/gcd(C, D)) B (C*D/gcd(C, D)) C*D C D gcd(C, D) gcd C D ((A-1)/C + (A-1)/D - (A-1)/(C*D/gcd(C, D))) (A-1)/C + (A-1)/D (A-1)/C (A-1) A 1 C (A-1)/D (A-1) A 1 D (A-1)/(C*D/gcd(C, D)) (A-1) A 1 (C*D/gcd(C, D)) C*D C D gcd(C, D) gcd C D System.out.print(ans) System.out.print System.out System System.out ans private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } gcd {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    } if(m < n) return gcd(n, m); m < n m n return gcd(n, m); gcd(n, m) gcd n m if(n == 0) return m; n == 0 n 0 return m; m return gcd(n, m % n); gcd(n, m % n) gcd n m % n m n long m m long n n // Main
    public static void main(String[] args) {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        // 全体数 - (B以下でCまたはDで割り切れるものの個数 - A-1以下でCまたはDで割り切れるものの個数)
        long ans = (B - A + 1) -
                ((B/C + B/D - B/(C*D/gcd(C, D))) - ((A-1)/C + (A-1)/D - (A-1)/(C*D/gcd(C, D))));
    System.out.print(ans);
    }


    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
} public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        // 全体数 - (B以下でCまたはDで割り切れるものの個数 - A-1以下でCまたはDで割り切れるものの個数)
        long ans = (B - A + 1) -
                ((B/C + B/D - B/(C*D/gcd(C, D))) - ((A-1)/C + (A-1)/D - (A-1)/(C*D/gcd(C, D))));
    System.out.print(ans);
    }


    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
} Main
import java.util.Scanner;

public class Main {

    private void solve() {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();

        // 全体数 - (B以下でCまたはDで割り切れるものの個数 - A-1以下でCまたはDで割り切れるものの個数)
        long ans = (B - A + 1) -
                ((B/C + B/D - B/(C*D/gcd(C, D))) - ((A-1)/C + (A-1)/D - (A-1)/(C*D/gcd(C, D))));
    System.out.print(ans);
    }


    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}
