import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        if(c < d) {
            long t = c;
            c = d;
            d = t;
        }
        long ans = (b - a + 1) - ((b / c - (a - 1) / c) + (b / d - (a - 1) / d)
                 - (b / lcm(c, d) - (a - 1) / lcm(c, d)));
        System.out.println(ans);
    }
    static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
    static long gcd(long m, long n) {
        long r = m % n;
        while(r > 0) {
            m = n;
            n = r;
            r = m % n;
        }
        return n;
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        if(c < d) {
            long t = c;
            c = d;
            d = t;
        }
        long ans = (b - a + 1) - ((b / c - (a - 1) / c) + (b / d - (a - 1) / d)
                 - (b / lcm(c, d) - (a - 1) / lcm(c, d)));
        System.out.println(ans);
    }
    static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
    static long gcd(long m, long n) {
        long r = m % n;
        while(r > 0) {
            m = n;
            n = r;
            r = m % n;
        }
        return n;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        if(c < d) {
            long t = c;
            c = d;
            d = t;
        }
        long ans = (b - a + 1) - ((b / c - (a - 1) / c) + (b / d - (a - 1) / d)
                 - (b / lcm(c, d) - (a - 1) / lcm(c, d)));
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        if(c < d) {
            long t = c;
            c = d;
            d = t;
        }
        long ans = (b - a + 1) - ((b / c - (a - 1) / c) + (b / d - (a - 1) / d)
                 - (b / lcm(c, d) - (a - 1) / lcm(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 b = sc.nextLong() b sc.nextLong() sc.nextLong sc c = sc.nextLong() c sc.nextLong() sc.nextLong sc d = sc.nextLong(); d sc.nextLong() sc.nextLong sc if(c < d) {
            long t = c;
            c = d;
            d = t;
        } c < d c d {
            long t = c;
            c = d;
            d = t;
        } long t = c; t c c = d c d d = t d t long ans = (b - a + 1) - ((b / c - (a - 1) / c) + (b / d - (a - 1) / d)
                 - (b / lcm(c, d) - (a - 1) / lcm(c, d))); ans (b - a + 1) - ((b / c - (a - 1) / c) + (b / d - (a - 1) / d)
                 - (b / lcm(c, d) - (a - 1) / lcm(c, d))) (b - a + 1) b - a b a 1 ((b / c - (a - 1) / c) + (b / d - (a - 1) / d)
                 - (b / lcm(c, d) - (a - 1) / lcm(c, d))) (b / c - (a - 1) / c) + (b / d - (a - 1) / d) (b / c - (a - 1) / c) b / c b c (a - 1) / c (a - 1) a 1 c (b / d - (a - 1) / d) b / d b d (a - 1) / d (a - 1) a 1 d (b / lcm(c, d) - (a - 1) / lcm(c, d)) b / lcm(c, d) b lcm(c, d) lcm c d (a - 1) / lcm(c, d) (a - 1) a 1 lcm(c, d) lcm c d System.out.println(ans) System.out.println System.out System System.out ans String[] args args 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 gcd(long m, long n) {
        long r = m % n;
        while(r > 0) {
            m = n;
            n = r;
            r = m % n;
        }
        return n;
    } gcd {
        long r = m % n;
        while(r > 0) {
            m = n;
            n = r;
            r = m % n;
        }
        return n;
    } long r = m % n; r m % n m n while(r > 0) {
            m = n;
            n = r;
            r = m % n;
        } r > 0 r 0 {
            m = n;
            n = r;
            r = m % n;
        } m = n m n n = r n r r = m % n r m % n m n return n; n long m m long n n public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        if(c < d) {
            long t = c;
            c = d;
            d = t;
        }
        long ans = (b - a + 1) - ((b / c - (a - 1) / c) + (b / d - (a - 1) / d)
                 - (b / lcm(c, d) - (a - 1) / lcm(c, d)));
        System.out.println(ans);
    }
    static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
    static long gcd(long m, long n) {
        long r = m % n;
        while(r > 0) {
            m = n;
            n = r;
            r = m % n;
        }
        return n;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        if(c < d) {
            long t = c;
            c = d;
            d = t;
        }
        long ans = (b - a + 1) - ((b / c - (a - 1) / c) + (b / d - (a - 1) / d)
                 - (b / lcm(c, d) - (a - 1) / lcm(c, d)));
        System.out.println(ans);
    }
    static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
    static long gcd(long m, long n) {
        long r = m % n;
        while(r > 0) {
            m = n;
            n = r;
            r = m % n;
        }
        return n;
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), c = sc.nextLong(), d = sc.nextLong();
        if(c < d) {
            long t = c;
            c = d;
            d = t;
        }
        long ans = (b - a + 1) - ((b / c - (a - 1) / c) + (b / d - (a - 1) / d)
                 - (b / lcm(c, d) - (a - 1) / lcm(c, d)));
        System.out.println(ans);
    }
    static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }
    static long gcd(long m, long n) {
        long r = m % n;
        while(r > 0) {
            m = n;
            n = r;
            r = m % n;
        }
        return n;
    }
}
