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 start = f(a-1,c,d);
        long end = f(b,c,d);

        System.out.print(end -start);
    }

    public static long f(long a, long b, long c) {
        long result = a;
        result -= a / b;
        result -= a / c;
        result += a / lcm(b, c);
        return result;
    }

    public static long gcd(long a, long b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static long lcm(long a, long b) {
        return a * b / gcd(a, 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 start = f(a-1,c,d);
        long end = f(b,c,d);

        System.out.print(end -start);
    }

    public static long f(long a, long b, long c) {
        long result = a;
        result -= a / b;
        result -= a / c;
        result += a / lcm(b, c);
        return result;
    }

    public static long gcd(long a, long b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static long lcm(long a, long b) {
        return a * b / gcd(a, 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 start = f(a-1,c,d);
        long end = f(b,c,d);

        System.out.print(end -start);
    } main {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        long start = f(a-1,c,d);
        long end = f(b,c,d);

        System.out.print(end -start);
    } 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 start = f(a-1,c,d); start f(a-1,c,d) f a-1 a 1 c d long end = f(b,c,d); end f(b,c,d) f b c d System.out.print(end -start) System.out.print System.out System System.out end -start end start String... args args public static long f(long a, long b, long c) {
        long result = a;
        result -= a / b;
        result -= a / c;
        result += a / lcm(b, c);
        return result;
    } f {
        long result = a;
        result -= a / b;
        result -= a / c;
        result += a / lcm(b, c);
        return result;
    } long result = a; result a result -= a / b result a / b a b result -= a / c result a / c a c result += a / lcm(b, c) result a / lcm(b, c) a lcm(b, c) lcm b c return result; result long a a long b b long c c public static long gcd(long a, long b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    } gcd {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    } if (a < b) return gcd(b, a); a < b a b return gcd(b, a); gcd(b, a) gcd b a if (b == 0) return a; b == 0 b 0 return a; a return gcd(b, a % b); gcd(b, a % b) gcd b a % b a b long a a long 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 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 start = f(a-1,c,d);
        long end = f(b,c,d);

        System.out.print(end -start);
    }

    public static long f(long a, long b, long c) {
        long result = a;
        result -= a / b;
        result -= a / c;
        result += a / lcm(b, c);
        return result;
    }

    public static long gcd(long a, long b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static long lcm(long a, long b) {
        return a * b / gcd(a, 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 start = f(a-1,c,d);
        long end = f(b,c,d);

        System.out.print(end -start);
    }

    public static long f(long a, long b, long c) {
        long result = a;
        result -= a / b;
        result -= a / c;
        result += a / lcm(b, c);
        return result;
    }

    public static long gcd(long a, long b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static long lcm(long a, long b) {
        return a * b / gcd(a, 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 start = f(a-1,c,d);
        long end = f(b,c,d);

        System.out.print(end -start);
    }

    public static long f(long a, long b, long c) {
        long result = a;
        result -= a / b;
        result -= a / c;
        result += a / lcm(b, c);
        return result;
    }

    public static long gcd(long a, long b) {
        if (a < b) return gcd(b, a);
        if (b == 0) return a;
        return gcd(b, a % b);
    }

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