import java.util.Scanner;

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 multipleC = b / c - (a - 1) / c; // cの倍数の数
        long multipleD = b / d - (a - 1) / d; // dの倍数の数
        long lcm = getLcm(c, d);
        long commonMultiple = b / lcm - (a - 1) / lcm; // cdの公倍数の数

        long result = b - (a - 1) - multipleC - multipleD + commonMultiple;
        System.out.println(result);
    }

    static long getLcm(long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return c / b;
    }
} 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();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long multipleC = b / c - (a - 1) / c; // cの倍数の数
        long multipleD = b / d - (a - 1) / d; // dの倍数の数
        long lcm = getLcm(c, d);
        long commonMultiple = b / lcm - (a - 1) / lcm; // cdの公倍数の数

        long result = b - (a - 1) - multipleC - multipleD + commonMultiple;
        System.out.println(result);
    }

    static long getLcm(long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return c / b;
    }
} 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 multipleC = b / c - (a - 1) / c; // cの倍数の数
        long multipleD = b / d - (a - 1) / d; // dの倍数の数
        long lcm = getLcm(c, d);
        long commonMultiple = b / lcm - (a - 1) / lcm; // cdの公倍数の数

        long result = b - (a - 1) - multipleC - multipleD + commonMultiple;
        System.out.println(result);
    } main {

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

        long multipleC = b / c - (a - 1) / c; // cの倍数の数
        long multipleD = b / d - (a - 1) / d; // dの倍数の数
        long lcm = getLcm(c, d);
        long commonMultiple = b / lcm - (a - 1) / lcm; // cdの公倍数の数

        long result = b - (a - 1) - multipleC - multipleD + commonMultiple;
        System.out.println(result);
    } 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 multipleC = b / c - (a - 1) / c; multipleC b / c - (a - 1) / c b / c b c (a - 1) / c (a - 1) a 1 c long multipleD = b / d - (a - 1) / d; multipleD b / d - (a - 1) / d b / d b d (a - 1) / d (a - 1) a 1 d long lcm = getLcm(c, d); lcm getLcm(c, d) getLcm c d long commonMultiple = b / lcm - (a - 1) / lcm; commonMultiple b / lcm - (a - 1) / lcm b / lcm b lcm (a - 1) / lcm (a - 1) a 1 lcm long result = b - (a - 1) - multipleC - multipleD + commonMultiple; result b - (a - 1) - multipleC - multipleD + commonMultiple b - (a - 1) - multipleC - multipleD multipleC b - (a - 1) - multipleC - multipleD b (a - 1) a 1 multipleC multipleD commonMultiple System.out.println(result) System.out.println System.out System System.out result String args[] args static long getLcm(long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return c / b;
    } getLcm {
        long temp;
        long c = a;
        c *= b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return c / b;
    } long temp; temp long c = a; c a c *= b c b while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        } (temp = a % b) != 0 (temp = a % b) temp a % b a b 0 {
            a = b;
            b = temp;
        } a = b a b b = temp b temp return c / b; c / b c b long a a long b b 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 multipleC = b / c - (a - 1) / c; // cの倍数の数
        long multipleD = b / d - (a - 1) / d; // dの倍数の数
        long lcm = getLcm(c, d);
        long commonMultiple = b / lcm - (a - 1) / lcm; // cdの公倍数の数

        long result = b - (a - 1) - multipleC - multipleD + commonMultiple;
        System.out.println(result);
    }

    static long getLcm(long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return c / b;
    }
} 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 multipleC = b / c - (a - 1) / c; // cの倍数の数
        long multipleD = b / d - (a - 1) / d; // dの倍数の数
        long lcm = getLcm(c, d);
        long commonMultiple = b / lcm - (a - 1) / lcm; // cdの公倍数の数

        long result = b - (a - 1) - multipleC - multipleD + commonMultiple;
        System.out.println(result);
    }

    static long getLcm(long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return c / b;
    }
} Main
import java.util.Scanner;

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 multipleC = b / c - (a - 1) / c; // cの倍数の数
        long multipleD = b / d - (a - 1) / d; // dの倍数の数
        long lcm = getLcm(c, d);
        long commonMultiple = b / lcm - (a - 1) / lcm; // cdの公倍数の数

        long result = b - (a - 1) - multipleC - multipleD + commonMultiple;
        System.out.println(result);
    }

    static long getLcm(long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return c / b;
    }
}
