import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

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

            long sum = 0;

            if(A%C == 0) {
                sum += B/C - A/C + 1;
            } else {
                sum += B/C - A/C;
            }

            if(A%D == 0) {
                sum += B/D - A/D + 1;
            } else {
                sum += B/D - A/D;
            }

            long lcm = Lcm.lcm(C,D);

            long lcmsum;
            if(lcm == -1) {
                lcmsum = 0;
            } else if(A%lcm == 0 ) {
                lcmsum = B/lcm - A/lcm + 1;
            } else {
                lcmsum = B/lcm - A/lcm;
            }
        System.out.println(B - A + 1 - sum + lcmsum);
    }
}

//import java.util.*;

class Lcm {
    //gcd 最大公約数
    public static long gcd(long m, long n) {
        if(m < n) return gcd(n,m);
        if(n == 0) return m;
        return gcd(n,m%n);
    }

    public static long lcm(long m, long n) {
        return m * n / gcd(m,n);
    }
} import java.util.*; util.* java class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

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

            long sum = 0;

            if(A%C == 0) {
                sum += B/C - A/C + 1;
            } else {
                sum += B/C - A/C;
            }

            if(A%D == 0) {
                sum += B/D - A/D + 1;
            } else {
                sum += B/D - A/D;
            }

            long lcm = Lcm.lcm(C,D);

            long lcmsum;
            if(lcm == -1) {
                lcmsum = 0;
            } else if(A%lcm == 0 ) {
                lcmsum = B/lcm - A/lcm + 1;
            } else {
                lcmsum = B/lcm - A/lcm;
            }
        System.out.println(B - A + 1 - sum + lcmsum);
    }
} Main public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

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

            long sum = 0;

            if(A%C == 0) {
                sum += B/C - A/C + 1;
            } else {
                sum += B/C - A/C;
            }

            if(A%D == 0) {
                sum += B/D - A/D + 1;
            } else {
                sum += B/D - A/D;
            }

            long lcm = Lcm.lcm(C,D);

            long lcmsum;
            if(lcm == -1) {
                lcmsum = 0;
            } else if(A%lcm == 0 ) {
                lcmsum = B/lcm - A/lcm + 1;
            } else {
                lcmsum = B/lcm - A/lcm;
            }
        System.out.println(B - A + 1 - sum + lcmsum);
    } main {
        Scanner sc = new Scanner(System.in);

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

            long sum = 0;

            if(A%C == 0) {
                sum += B/C - A/C + 1;
            } else {
                sum += B/C - A/C;
            }

            if(A%D == 0) {
                sum += B/D - A/D + 1;
            } else {
                sum += B/D - A/D;
            }

            long lcm = Lcm.lcm(C,D);

            long lcmsum;
            if(lcm == -1) {
                lcmsum = 0;
            } else if(A%lcm == 0 ) {
                lcmsum = B/lcm - A/lcm + 1;
            } else {
                lcmsum = B/lcm - A/lcm;
            }
        System.out.println(B - A + 1 - sum + lcmsum);
    } 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 sum = 0; sum 0 if(A%C == 0) {
                sum += B/C - A/C + 1;
            } else {
                sum += B/C - A/C;
            } A%C == 0 A%C A C 0 {
                sum += B/C - A/C + 1;
            } sum += B/C - A/C + 1 sum B/C - A/C + 1 B/C - A/C B/C B C A/C A C 1 {
                sum += B/C - A/C;
            } sum += B/C - A/C sum B/C - A/C B/C B C A/C A C if(A%D == 0) {
                sum += B/D - A/D + 1;
            } else {
                sum += B/D - A/D;
            } A%D == 0 A%D A D 0 {
                sum += B/D - A/D + 1;
            } sum += B/D - A/D + 1 sum B/D - A/D + 1 B/D - A/D B/D B D A/D A D 1 {
                sum += B/D - A/D;
            } sum += B/D - A/D sum B/D - A/D B/D B D A/D A D long lcm = Lcm.lcm(C,D); lcm Lcm.lcm(C,D) Lcm.lcm Lcm C D long lcmsum; lcmsum if(lcm == -1) {
                lcmsum = 0;
            } else if(A%lcm == 0 ) {
                lcmsum = B/lcm - A/lcm + 1;
            } else {
                lcmsum = B/lcm - A/lcm;
            } lcm == -1 lcm -1 1 {
                lcmsum = 0;
            } lcmsum = 0 lcmsum 0 if(A%lcm == 0 ) {
                lcmsum = B/lcm - A/lcm + 1;
            } else {
                lcmsum = B/lcm - A/lcm;
            } A%lcm == 0 A%lcm A lcm 0 {
                lcmsum = B/lcm - A/lcm + 1;
            } lcmsum = B/lcm - A/lcm + 1 lcmsum B/lcm - A/lcm + 1 B/lcm - A/lcm B/lcm B lcm A/lcm A lcm 1 {
                lcmsum = B/lcm - A/lcm;
            } lcmsum = B/lcm - A/lcm lcmsum B/lcm - A/lcm B/lcm B lcm A/lcm A lcm System.out.println(B - A + 1 - sum + lcmsum) System.out.println System.out System System.out B - A + 1 - sum + lcmsum B - A + 1 - sum B - A + 1 B - A B A 1 sum lcmsum String args[] args class Lcm {
    //gcd 最大公約数
    public static long gcd(long m, long n) {
        if(m < n) return gcd(n,m);
        if(n == 0) return m;
        return gcd(n,m%n);
    }

    public static long lcm(long m, long n) {
        return m * n / gcd(m,n);
    }
} Lcm //gcd 最大公約数
    public 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 public static long lcm(long m, long n) {
        return m * n / gcd(m,n);
    } lcm {
        return m * n / gcd(m,n);
    } return m * n / gcd(m,n); m * n / gcd(m,n) m * n m n gcd(m,n) gcd m n long m m long n n
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);

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

            long sum = 0;

            if(A%C == 0) {
                sum += B/C - A/C + 1;
            } else {
                sum += B/C - A/C;
            }

            if(A%D == 0) {
                sum += B/D - A/D + 1;
            } else {
                sum += B/D - A/D;
            }

            long lcm = Lcm.lcm(C,D);

            long lcmsum;
            if(lcm == -1) {
                lcmsum = 0;
            } else if(A%lcm == 0 ) {
                lcmsum = B/lcm - A/lcm + 1;
            } else {
                lcmsum = B/lcm - A/lcm;
            }
        System.out.println(B - A + 1 - sum + lcmsum);
    }
}

//import java.util.*;

class Lcm {
    //gcd 最大公約数
    public static long gcd(long m, long n) {
        if(m < n) return gcd(n,m);
        if(n == 0) return m;
        return gcd(n,m%n);
    }

    public static long lcm(long m, long n) {
        return m * n / gcd(m,n);
    }
}