import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        a--;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long total = b - a;

        long divD = b / d - a / d;
        long divC = b / c - a / c;

        long lcm = getLcm(c, d);
        long divL = b / lcm - a / lcm;

        System.out.println(total - (divD + divC - divL));

    }

    private static long getLcm(long n, long m) {

        long bn = n;
        long bm = m;

        while (n != m) {
            if (n < m) {
                n += bn;
            } else {
                m += bm;
            }
        }
        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();
        a--;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long total = b - a;

        long divD = b / d - a / d;
        long divC = b / c - a / c;

        long lcm = getLcm(c, d);
        long divL = b / lcm - a / lcm;

        System.out.println(total - (divD + divC - divL));

    }

    private static long getLcm(long n, long m) {

        long bn = n;
        long bm = m;

        while (n != m) {
            if (n < m) {
                n += bn;
            } else {
                m += bm;
            }
        }
        return n;
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        a--;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long total = b - a;

        long divD = b / d - a / d;
        long divC = b / c - a / c;

        long lcm = getLcm(c, d);
        long divL = b / lcm - a / lcm;

        System.out.println(total - (divD + divC - divL));

    } main {

        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        a--;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long total = b - a;

        long divD = b / d - a / d;
        long divC = b / c - a / c;

        long lcm = getLcm(c, d);
        long divL = b / lcm - a / lcm;

        System.out.println(total - (divD + divC - divL));

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = sc.nextLong(); a sc.nextLong() sc.nextLong sc a-- a 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 total = b - a; total b - a b a long divD = b / d - a / d; divD b / d - a / d b / d b d a / d a d long divC = b / c - a / c; divC b / c - a / c b / c b c a / c a c long lcm = getLcm(c, d); lcm getLcm(c, d) getLcm c d long divL = b / lcm - a / lcm; divL b / lcm - a / lcm b / lcm b lcm a / lcm a lcm System.out.println(total - (divD + divC - divL)) System.out.println System.out System System.out total - (divD + divC - divL) total (divD + divC - divL) divD + divC divD divC divL String[] args args private static long getLcm(long n, long m) {

        long bn = n;
        long bm = m;

        while (n != m) {
            if (n < m) {
                n += bn;
            } else {
                m += bm;
            }
        }
        return n;
    } getLcm {

        long bn = n;
        long bm = m;

        while (n != m) {
            if (n < m) {
                n += bn;
            } else {
                m += bm;
            }
        }
        return n;
    } long bn = n; bn n long bm = m; bm m while (n != m) {
            if (n < m) {
                n += bn;
            } else {
                m += bm;
            }
        } n != m n m {
            if (n < m) {
                n += bn;
            } else {
                m += bm;
            }
        } if (n < m) {
                n += bn;
            } else {
                m += bm;
            } n < m n m {
                n += bn;
            } n += bn n bn {
                m += bm;
            } m += bm m bm return n; n long n n long m m public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        a--;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long total = b - a;

        long divD = b / d - a / d;
        long divC = b / c - a / c;

        long lcm = getLcm(c, d);
        long divL = b / lcm - a / lcm;

        System.out.println(total - (divD + divC - divL));

    }

    private static long getLcm(long n, long m) {

        long bn = n;
        long bm = m;

        while (n != m) {
            if (n < m) {
                n += bn;
            } else {
                m += bm;
            }
        }
        return n;
    }
} public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        a--;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long total = b - a;

        long divD = b / d - a / d;
        long divC = b / c - a / c;

        long lcm = getLcm(c, d);
        long divL = b / lcm - a / lcm;

        System.out.println(total - (divD + divC - divL));

    }

    private static long getLcm(long n, long m) {

        long bn = n;
        long bm = m;

        while (n != m) {
            if (n < m) {
                n += bn;
            } else {
                m += bm;
            }
        }
        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();
        a--;
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long total = b - a;

        long divD = b / d - a / d;
        long divC = b / c - a / c;

        long lcm = getLcm(c, d);
        long divL = b / lcm - a / lcm;

        System.out.println(total - (divD + divC - divL));

    }

    private static long getLcm(long n, long m) {

        long bn = n;
        long bm = m;

        while (n != m) {
            if (n < m) {
                n += bn;
            } else {
                m += bm;
            }
        }
        return n;
    }
}