import java.util.*;

public 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 count = b - a + 1;

        count -= counter(a, b, c);
        count -= counter(a, b, d);
        count += counter(a, b, lcm(c, d));

        System.out.println(count);
        sc.close();
    }

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

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

    static long counter(long a, long b, long n){
        if(a%n == 0)
            return ((b/n) - (a/n) + 1);
        else
            return ((b/n) - (a/n));
    }
} import java.util.*; util.* java public 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 count = b - a + 1;

        count -= counter(a, b, c);
        count -= counter(a, b, d);
        count += counter(a, b, lcm(c, d));

        System.out.println(count);
        sc.close();
    }

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

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

    static long counter(long a, long b, long n){
        if(a%n == 0)
            return ((b/n) - (a/n) + 1);
        else
            return ((b/n) - (a/n));
    }
} 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 count = b - a + 1;

        count -= counter(a, b, c);
        count -= counter(a, b, d);
        count += counter(a, b, lcm(c, d));

        System.out.println(count);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long count = b - a + 1;

        count -= counter(a, b, c);
        count -= counter(a, b, d);
        count += counter(a, b, lcm(c, d));

        System.out.println(count);
        sc.close();
    } 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 count = b - a + 1; count b - a + 1 b - a b a 1 count -= counter(a, b, c) count counter(a, b, c) counter a b c count -= counter(a, b, d) count counter(a, b, d) counter a b d count += counter(a, b, lcm(c, d)) count counter(a, b, lcm(c, d)) counter a b lcm(c, d) lcm c d System.out.println(count) System.out.println System.out System System.out count sc.close() sc.close sc String args[] args 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 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 static long counter(long a, long b, long n){
        if(a%n == 0)
            return ((b/n) - (a/n) + 1);
        else
            return ((b/n) - (a/n));
    } counter {
        if(a%n == 0)
            return ((b/n) - (a/n) + 1);
        else
            return ((b/n) - (a/n));
    } if(a%n == 0)
            return ((b/n) - (a/n) + 1);
        else
            return ((b/n) - (a/n)); a%n == 0 a%n a n 0 return ((b/n) - (a/n) + 1); ((b/n) - (a/n) + 1) (b/n) - (a/n) (b/n) b n (a/n) a n 1 return ((b/n) - (a/n)); ((b/n) - (a/n)) (b/n) b n (a/n) a n long a a long b b long n n public 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 count = b - a + 1;

        count -= counter(a, b, c);
        count -= counter(a, b, d);
        count += counter(a, b, lcm(c, d));

        System.out.println(count);
        sc.close();
    }

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

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

    static long counter(long a, long b, long n){
        if(a%n == 0)
            return ((b/n) - (a/n) + 1);
        else
            return ((b/n) - (a/n));
    }
} public 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 count = b - a + 1;

        count -= counter(a, b, c);
        count -= counter(a, b, d);
        count += counter(a, b, lcm(c, d));

        System.out.println(count);
        sc.close();
    }

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

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

    static long counter(long a, long b, long n){
        if(a%n == 0)
            return ((b/n) - (a/n) + 1);
        else
            return ((b/n) - (a/n));
    }
} Main
import java.util.*;

public 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 count = b - a + 1;

        count -= counter(a, b, c);
        count -= counter(a, b, d);
        count += counter(a, b, lcm(c, d));

        System.out.println(count);
        sc.close();
    }

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

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

    static long counter(long a, long b, long n){
        if(a%n == 0)
            return ((b/n) - (a/n) + 1);
        else
            return ((b/n) - (a/n));
    }
}