import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        /*
        方針
        A以上で割り切れる-B以上で割り切れるやつ
        CでもDでも割り切れるやつを足す
        ここでCでもDでも割り切れる数はCDの最小公倍数
         */

        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        long ans = 0;

        ans = f(B, C, D) - f(A - 1, C, D);

        System.out.println(ans);
    }

    static long f(long W, long C, long D) {
        long quanty = W;
        quanty -= W / C;
        quanty -= W / D;
        quanty += W / lcm(C, D);
        return quanty;
    }

    static long lcm(long C, long D) {
        return C * D / gcd(C, D);
    }

    static long gcd(long C, long D) {
        return D > 0 ? gcd(D, C % D) : C;
    }

} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        /*
        方針
        A以上で割り切れる-B以上で割り切れるやつ
        CでもDでも割り切れるやつを足す
        ここでCでもDでも割り切れる数はCDの最小公倍数
         */

        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        long ans = 0;

        ans = f(B, C, D) - f(A - 1, C, D);

        System.out.println(ans);
    }

    static long f(long W, long C, long D) {
        long quanty = W;
        quanty -= W / C;
        quanty -= W / D;
        quanty += W / lcm(C, D);
        return quanty;
    }

    static long lcm(long C, long D) {
        return C * D / gcd(C, D);
    }

    static long gcd(long C, long D) {
        return D > 0 ? gcd(D, C % D) : C;
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        /*
        方針
        A以上で割り切れる-B以上で割り切れるやつ
        CでもDでも割り切れるやつを足す
        ここでCでもDでも割り切れる数はCDの最小公倍数
         */

        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        long ans = 0;

        ans = f(B, C, D) - f(A - 1, C, D);

        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        /*
        方針
        A以上で割り切れる-B以上で割り切れるやつ
        CでもDでも割り切れるやつを足す
        ここでCでもDでも割り切れる数はCDの最小公倍数
         */

        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        long ans = 0;

        ans = f(B, C, D) - f(A - 1, C, D);

        System.out.println(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 = 0; ans 0 ans = f(B, C, D) - f(A - 1, C, D) ans f(B, C, D) - f(A - 1, C, D) f(B, C, D) f B C D f(A - 1, C, D) f A - 1 A 1 C D System.out.println(ans) System.out.println System.out System System.out ans String[] args args static long f(long W, long C, long D) {
        long quanty = W;
        quanty -= W / C;
        quanty -= W / D;
        quanty += W / lcm(C, D);
        return quanty;
    } f {
        long quanty = W;
        quanty -= W / C;
        quanty -= W / D;
        quanty += W / lcm(C, D);
        return quanty;
    } long quanty = W; quanty W quanty -= W / C quanty W / C W C quanty -= W / D quanty W / D W D quanty += W / lcm(C, D) quanty W / lcm(C, D) W lcm(C, D) lcm C D return quanty; quanty long W W long C C long D D static long lcm(long C, long D) {
        return C * D / gcd(C, D);
    } lcm {
        return C * D / gcd(C, D);
    } return C * D / gcd(C, D); C * D / gcd(C, D) C * D C D gcd(C, D) gcd C D long C C long D D static long gcd(long C, long D) {
        return D > 0 ? gcd(D, C % D) : C;
    } gcd {
        return D > 0 ? gcd(D, C % D) : C;
    } return D > 0 ? gcd(D, C % D) : C; D > 0 ? gcd(D, C % D) : C D > 0 D 0 gcd(D, C % D) gcd D C % D C D C long C C long D D public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        /*
        方針
        A以上で割り切れる-B以上で割り切れるやつ
        CでもDでも割り切れるやつを足す
        ここでCでもDでも割り切れる数はCDの最小公倍数
         */

        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        long ans = 0;

        ans = f(B, C, D) - f(A - 1, C, D);

        System.out.println(ans);
    }

    static long f(long W, long C, long D) {
        long quanty = W;
        quanty -= W / C;
        quanty -= W / D;
        quanty += W / lcm(C, D);
        return quanty;
    }

    static long lcm(long C, long D) {
        return C * D / gcd(C, D);
    }

    static long gcd(long C, long D) {
        return D > 0 ? gcd(D, C % D) : C;
    }

} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        /*
        方針
        A以上で割り切れる-B以上で割り切れるやつ
        CでもDでも割り切れるやつを足す
        ここでCでもDでも割り切れる数はCDの最小公倍数
         */

        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        long ans = 0;

        ans = f(B, C, D) - f(A - 1, C, D);

        System.out.println(ans);
    }

    static long f(long W, long C, long D) {
        long quanty = W;
        quanty -= W / C;
        quanty -= W / D;
        quanty += W / lcm(C, D);
        return quanty;
    }

    static long lcm(long C, long D) {
        return C * D / gcd(C, D);
    }

    static long gcd(long C, long D) {
        return D > 0 ? gcd(D, C % D) : C;
    }

} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        /*
        方針
        A以上で割り切れる-B以上で割り切れるやつ
        CでもDでも割り切れるやつを足す
        ここでCでもDでも割り切れる数はCDの最小公倍数
         */

        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long D = sc.nextLong();
        long ans = 0;

        ans = f(B, C, D) - f(A - 1, C, D);

        System.out.println(ans);
    }

    static long f(long W, long C, long D) {
        long quanty = W;
        quanty -= W / C;
        quanty -= W / D;
        quanty += W / lcm(C, D);
        return quanty;
    }

    static long lcm(long C, long D) {
        return C * D / gcd(C, D);
    }

    static long gcd(long C, long D) {
        return D > 0 ? gcd(D, C % D) : C;
    }

}
