// 全然わかんねぇ数学できねぇ俺らは感覚でコードを書いている
// 参考 -> #6056988
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 ans = f(b, c, d) - f(a-1, c, d);

        System.out.println(ans);
    }

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

    static long f(long n, long c, long d) {
        long x = n;
        x -= n / c;
        x -= n / d;
        long tmp = c / gcd(c, d) * d;
        x += n / tmp;
        return x;
    }
} 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 ans = f(b, c, d) - f(a-1, c, d);

        System.out.println(ans);
    }

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

    static long f(long n, long c, long d) {
        long x = n;
        x -= n / c;
        x -= n / d;
        long tmp = c / gcd(c, d) * d;
        x += n / tmp;
        return x;
    }
} 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 ans = f(b, c, d) - f(a-1, c, d);

        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

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

        System.out.println(ans);
    } 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 ans = f(b, c, d) - f(a-1, c, d); ans f(b, c, d) - f(a-1, c, d) f(b, c, d) f b c d f(a-1, c, d) f a-1 a 1 c d System.out.println(ans) System.out.println System.out System System.out ans String[] args args static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    } gcd {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    } 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 static long f(long n, long c, long d) {
        long x = n;
        x -= n / c;
        x -= n / d;
        long tmp = c / gcd(c, d) * d;
        x += n / tmp;
        return x;
    } f {
        long x = n;
        x -= n / c;
        x -= n / d;
        long tmp = c / gcd(c, d) * d;
        x += n / tmp;
        return x;
    } long x = n; x n x -= n / c x n / c n c x -= n / d x n / d n d long tmp = c / gcd(c, d) * d; tmp c / gcd(c, d) * d c / gcd(c, d) c gcd(c, d) gcd c d d x += n / tmp x n / tmp n tmp return x; x long n n long c c long d d 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 ans = f(b, c, d) - f(a-1, c, d);

        System.out.println(ans);
    }

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

    static long f(long n, long c, long d) {
        long x = n;
        x -= n / c;
        x -= n / d;
        long tmp = c / gcd(c, d) * d;
        x += n / tmp;
        return x;
    }
} 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 ans = f(b, c, d) - f(a-1, c, d);

        System.out.println(ans);
    }

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

    static long f(long n, long c, long d) {
        long x = n;
        x -= n / c;
        x -= n / d;
        long tmp = c / gcd(c, d) * d;
        x += n / tmp;
        return x;
    }
} Main
// 全然わかんねぇ数学できねぇ俺らは感覚でコードを書いている
// 参考 -> #6056988
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 ans = f(b, c, d) - f(a-1, c, d);

        System.out.println(ans);
    }

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

    static long f(long n, long c, long d) {
        long x = n;
        x -= n / c;
        x -= n / d;
        long tmp = c / gcd(c, d) * d;
        x += n / tmp;
        return x;
    }
}