public class Main {
    public static void main(String[] args) {
        java.util.Scanner sc = new java.util.Scanner(System.in);

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();

        System.out.println(B - A + 1 - MyLib.countMultiples(A, B, C) - MyLib.countMultiples(A, B, D) + MyLib.countMultiples(A, B, MyLib.lcm(C, D)));
    }
}

class MyLib {
    public static int gcd(int a, int b) {
        int tmp;
        while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }

    public static long gcd(long a, long b) {
        long tmp;
        while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }

    public static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }

    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    public static long countMultiples(long min, long max, long base) {
        return max / base - (min - 1) / base;
    }
} public class Main {
    public static void main(String[] args) {
        java.util.Scanner sc = new java.util.Scanner(System.in);

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();

        System.out.println(B - A + 1 - MyLib.countMultiples(A, B, C) - MyLib.countMultiples(A, B, D) + MyLib.countMultiples(A, B, MyLib.lcm(C, D)));
    }
} Main public static void main(String[] args) {
        java.util.Scanner sc = new java.util.Scanner(System.in);

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();

        System.out.println(B - A + 1 - MyLib.countMultiples(A, B, C) - MyLib.countMultiples(A, B, D) + MyLib.countMultiples(A, B, MyLib.lcm(C, D)));
    } main {
        java.util.Scanner sc = new java.util.Scanner(System.in);

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();

        System.out.println(B - A + 1 - MyLib.countMultiples(A, B, C) - MyLib.countMultiples(A, B, D) + MyLib.countMultiples(A, B, MyLib.lcm(C, D)));
    } java.util.Scanner sc = new java.util.Scanner(System.in); sc new java.util.Scanner(System.in) final long A = sc.nextLong(); A sc.nextLong() sc.nextLong sc final long B = sc.nextLong(); B sc.nextLong() sc.nextLong sc final long C = sc.nextLong(); C sc.nextLong() sc.nextLong sc final long D = sc.nextLong(); D sc.nextLong() sc.nextLong sc System.out.println(B - A + 1 - MyLib.countMultiples(A, B, C) - MyLib.countMultiples(A, B, D) + MyLib.countMultiples(A, B, MyLib.lcm(C, D))) System.out.println System.out System System.out B - A + 1 - MyLib.countMultiples(A, B, C) - MyLib.countMultiples(A, B, D) + MyLib.countMultiples(A, B, MyLib.lcm(C, D)) B - A + 1 - MyLib.countMultiples(A, B, C) - MyLib.countMultiples(A, B, D) B - A + 1 - MyLib.countMultiples(A, B, C) - MyLib.countMultiples(A, B, D) B - A + 1 B - A B A 1 MyLib.countMultiples(A, B, C) MyLib.countMultiples MyLib A B C MyLib.countMultiples(A, B, D) MyLib.countMultiples MyLib A B D MyLib.countMultiples(A, B, MyLib.lcm(C, D)) MyLib.countMultiples MyLib A B MyLib.lcm(C, D) MyLib.lcm MyLib C D String[] args args class MyLib {
    public static int gcd(int a, int b) {
        int tmp;
        while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }

    public static long gcd(long a, long b) {
        long tmp;
        while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }

    public static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }

    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    public static long countMultiples(long min, long max, long base) {
        return max / base - (min - 1) / base;
    }
} MyLib public static int gcd(int a, int b) {
        int tmp;
        while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    } gcd {
        int tmp;
        while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    } int tmp; tmp while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        } b != 0 b 0 {
            tmp = a % b;
            a = b;
            b = tmp;
        } tmp = a % b tmp a % b a b a = b a b b = tmp b tmp return a; a int a a int b b public static long gcd(long a, long b) {
        long tmp;
        while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    } gcd {
        long tmp;
        while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    } long tmp; tmp while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        } b != 0 b 0 {
            tmp = a % b;
            a = b;
            b = tmp;
        } tmp = a % b tmp a % b a b a = b a b b = tmp b tmp return a; a long a a long b b public static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    } lcm {
        return a * b / gcd(a, b);
    } return a * b / gcd(a, b); a * b / gcd(a, b) a * b a b gcd(a, b) gcd a b int a a int b b public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    } lcm {
        return a * b / gcd(a, b);
    } return a * b / gcd(a, b); a * b / gcd(a, b) a * b a b gcd(a, b) gcd a b long a a long b b public static long countMultiples(long min, long max, long base) {
        return max / base - (min - 1) / base;
    } countMultiples {
        return max / base - (min - 1) / base;
    } return max / base - (min - 1) / base; max / base - (min - 1) / base max / base max base (min - 1) / base (min - 1) min 1 base long min min long max max long base base public class Main {
    public static void main(String[] args) {
        java.util.Scanner sc = new java.util.Scanner(System.in);

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();

        System.out.println(B - A + 1 - MyLib.countMultiples(A, B, C) - MyLib.countMultiples(A, B, D) + MyLib.countMultiples(A, B, MyLib.lcm(C, D)));
    }
} public class Main {
    public static void main(String[] args) {
        java.util.Scanner sc = new java.util.Scanner(System.in);

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();

        System.out.println(B - A + 1 - MyLib.countMultiples(A, B, C) - MyLib.countMultiples(A, B, D) + MyLib.countMultiples(A, B, MyLib.lcm(C, D)));
    }
} Main
public class Main {
    public static void main(String[] args) {
        java.util.Scanner sc = new java.util.Scanner(System.in);

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();

        System.out.println(B - A + 1 - MyLib.countMultiples(A, B, C) - MyLib.countMultiples(A, B, D) + MyLib.countMultiples(A, B, MyLib.lcm(C, D)));
    }
}

class MyLib {
    public static int gcd(int a, int b) {
        int tmp;
        while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }

    public static long gcd(long a, long b) {
        long tmp;
        while (b != 0) {
            tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }

    public static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }

    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    public static long countMultiples(long min, long max, long base) {
        return max / base - (min - 1) / base;
    }
}