import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());

        // 主処理
        long total = b - (a - 1);
        long countC = b / c - (a - 1) / c; // bまでの約数の数 - aまでの約数の数
        long countD = b / d - (a - 1) / d; // bまでの約数の数 - aまでの約数の数
        long cm = b / lcm((int) c, (int) d) - (a - 1) / lcm((int) c, (int) d); // aからbまでのcとdの公倍数の数
        long result = total - countC - countD + cm;

        // 出力
        System.out.println(result);
        sc.close();
    }

    public static long lcm(int a, int b) {
        int 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 = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());

        // 主処理
        long total = b - (a - 1);
        long countC = b / c - (a - 1) / c; // bまでの約数の数 - aまでの約数の数
        long countD = b / d - (a - 1) / d; // bまでの約数の数 - aまでの約数の数
        long cm = b / lcm((int) c, (int) d) - (a - 1) / lcm((int) c, (int) d); // aからbまでのcとdの公倍数の数
        long result = total - countC - countD + cm;

        // 出力
        System.out.println(result);
        sc.close();
    }

    public static long lcm(int a, int b) {
        int 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 = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());

        // 主処理
        long total = b - (a - 1);
        long countC = b / c - (a - 1) / c; // bまでの約数の数 - aまでの約数の数
        long countD = b / d - (a - 1) / d; // bまでの約数の数 - aまでの約数の数
        long cm = b / lcm((int) c, (int) d) - (a - 1) / lcm((int) c, (int) d); // aからbまでのcとdの公倍数の数
        long result = total - countC - countD + cm;

        // 出力
        System.out.println(result);
        sc.close();
    } main {

        // 入力
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());

        // 主処理
        long total = b - (a - 1);
        long countC = b / c - (a - 1) / c; // bまでの約数の数 - aまでの約数の数
        long countD = b / d - (a - 1) / d; // bまでの約数の数 - aまでの約数の数
        long cm = b / lcm((int) c, (int) d) - (a - 1) / lcm((int) c, (int) d); // aからbまでのcとdの公倍数の数
        long result = total - countC - countD + cm;

        // 出力
        System.out.println(result);
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long a = Long.parseLong(sc.next()); a Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long b = Long.parseLong(sc.next()); b Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long c = Long.parseLong(sc.next()); c Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long d = Long.parseLong(sc.next()); d Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long total = b - (a - 1); total b - (a - 1) b (a - 1) a 1 long countC = b / c - (a - 1) / c; countC b / c - (a - 1) / c b / c b c (a - 1) / c (a - 1) a 1 c long countD = b / d - (a - 1) / d; countD b / d - (a - 1) / d b / d b d (a - 1) / d (a - 1) a 1 d long cm = b / lcm((int) c, (int) d) - (a - 1) / lcm((int) c, (int) d); cm b / lcm((int) c, (int) d) - (a - 1) / lcm((int) c, (int) d) b / lcm((int) c, (int) d) b lcm((int) c, (int) d) lcm (int) c (int) d (a - 1) / lcm((int) c, (int) d) (a - 1) a 1 lcm((int) c, (int) d) lcm (int) c (int) d long result = total - countC - countD + cm; result total - countC - countD + cm total - countC - countD total - countC - countD total countC countD cm System.out.println(result) System.out.println System.out System System.out result sc.close() sc.close sc String args[] args public static long lcm(int a, int b) {
        int temp;
        long c = a;
        c *= b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return c / b;
    } lcm {
        int temp;
        long c = a;
        c *= b;
        while ((temp = a % b) != 0) {
            a = b;
            b = temp;
        }
        return c / b;
    } int 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 int a a int b b public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());

        // 主処理
        long total = b - (a - 1);
        long countC = b / c - (a - 1) / c; // bまでの約数の数 - aまでの約数の数
        long countD = b / d - (a - 1) / d; // bまでの約数の数 - aまでの約数の数
        long cm = b / lcm((int) c, (int) d) - (a - 1) / lcm((int) c, (int) d); // aからbまでのcとdの公倍数の数
        long result = total - countC - countD + cm;

        // 出力
        System.out.println(result);
        sc.close();
    }

    public static long lcm(int a, int b) {
        int 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 = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());

        // 主処理
        long total = b - (a - 1);
        long countC = b / c - (a - 1) / c; // bまでの約数の数 - aまでの約数の数
        long countD = b / d - (a - 1) / d; // bまでの約数の数 - aまでの約数の数
        long cm = b / lcm((int) c, (int) d) - (a - 1) / lcm((int) c, (int) d); // aからbまでのcとdの公倍数の数
        long result = total - countC - countD + cm;

        // 出力
        System.out.println(result);
        sc.close();
    }

    public static long lcm(int a, int b) {
        int 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 = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());

        // 主処理
        long total = b - (a - 1);
        long countC = b / c - (a - 1) / c; // bまでの約数の数 - aまでの約数の数
        long countD = b / d - (a - 1) / d; // bまでの約数の数 - aまでの約数の数
        long cm = b / lcm((int) c, (int) d) - (a - 1) / lcm((int) c, (int) d); // aからbまでのcとdの公倍数の数
        long result = total - countC - countD + cm;

        // 出力
        System.out.println(result);
        sc.close();
    }

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