// package c;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        long a = stdin.nextLong();
        long b = stdin.nextLong();
        long c = stdin.nextLong();
        long d = stdin.nextLong();

        // e: cとdの最小公倍数
        long e = (c * d) / gcd(c, d);

        // x: cで割り切れるもの
        // y: dで割り切れるもの
        // z: cでもdでも割り切れるもの
        long x = ((b / c * c) - (div(a, c) * c)) / c + 1;
        long y = ((b / d * d) - (div(a, d) * d)) / d + 1;
        long z = ((b / e * e) - (div(a, e) * e)) / e + 1;
        System.out.println((b - a + 1) - x - y + z);
    }

    public static long gcd(long x, long y) {
        if (x < y) {
            return gcd(y, x);
        }

        return x % y == 0 ? y : gcd(y, x % y);
    }

    public static long div(long x, long y) {
        return x % y == 0 ? x / y : x / y + 1;
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        long a = stdin.nextLong();
        long b = stdin.nextLong();
        long c = stdin.nextLong();
        long d = stdin.nextLong();

        // e: cとdの最小公倍数
        long e = (c * d) / gcd(c, d);

        // x: cで割り切れるもの
        // y: dで割り切れるもの
        // z: cでもdでも割り切れるもの
        long x = ((b / c * c) - (div(a, c) * c)) / c + 1;
        long y = ((b / d * d) - (div(a, d) * d)) / d + 1;
        long z = ((b / e * e) - (div(a, e) * e)) / e + 1;
        System.out.println((b - a + 1) - x - y + z);
    }

    public static long gcd(long x, long y) {
        if (x < y) {
            return gcd(y, x);
        }

        return x % y == 0 ? y : gcd(y, x % y);
    }

    public static long div(long x, long y) {
        return x % y == 0 ? x / y : x / y + 1;
    }
} Main public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        long a = stdin.nextLong();
        long b = stdin.nextLong();
        long c = stdin.nextLong();
        long d = stdin.nextLong();

        // e: cとdの最小公倍数
        long e = (c * d) / gcd(c, d);

        // x: cで割り切れるもの
        // y: dで割り切れるもの
        // z: cでもdでも割り切れるもの
        long x = ((b / c * c) - (div(a, c) * c)) / c + 1;
        long y = ((b / d * d) - (div(a, d) * d)) / d + 1;
        long z = ((b / e * e) - (div(a, e) * e)) / e + 1;
        System.out.println((b - a + 1) - x - y + z);
    } main {
        Scanner stdin = new Scanner(System.in);
        long a = stdin.nextLong();
        long b = stdin.nextLong();
        long c = stdin.nextLong();
        long d = stdin.nextLong();

        // e: cとdの最小公倍数
        long e = (c * d) / gcd(c, d);

        // x: cで割り切れるもの
        // y: dで割り切れるもの
        // z: cでもdでも割り切れるもの
        long x = ((b / c * c) - (div(a, c) * c)) / c + 1;
        long y = ((b / d * d) - (div(a, d) * d)) / d + 1;
        long z = ((b / e * e) - (div(a, e) * e)) / e + 1;
        System.out.println((b - a + 1) - x - y + z);
    } Scanner stdin = new Scanner(System.in); stdin new Scanner(System.in) long a = stdin.nextLong(); a stdin.nextLong() stdin.nextLong stdin long b = stdin.nextLong(); b stdin.nextLong() stdin.nextLong stdin long c = stdin.nextLong(); c stdin.nextLong() stdin.nextLong stdin long d = stdin.nextLong(); d stdin.nextLong() stdin.nextLong stdin long e = (c * d) / gcd(c, d); e (c * d) / gcd(c, d) (c * d) c d gcd(c, d) gcd c d long x = ((b / c * c) - (div(a, c) * c)) / c + 1; x ((b / c * c) - (div(a, c) * c)) / c + 1 ((b / c * c) - (div(a, c) * c)) / c ((b / c * c) - (div(a, c) * c)) (b / c * c) b / c b c c (div(a, c) * c) div(a, c) div a c c c 1 long y = ((b / d * d) - (div(a, d) * d)) / d + 1; y ((b / d * d) - (div(a, d) * d)) / d + 1 ((b / d * d) - (div(a, d) * d)) / d ((b / d * d) - (div(a, d) * d)) (b / d * d) b / d b d d (div(a, d) * d) div(a, d) div a d d d 1 long z = ((b / e * e) - (div(a, e) * e)) / e + 1; z ((b / e * e) - (div(a, e) * e)) / e + 1 ((b / e * e) - (div(a, e) * e)) / e ((b / e * e) - (div(a, e) * e)) (b / e * e) b / e b e e (div(a, e) * e) div(a, e) div a e e e 1 System.out.println((b - a + 1) - x - y + z) System.out.println System.out System System.out (b - a + 1) - x - y + z (b - a + 1) - x - y (b - a + 1) - x - y (b - a + 1) b - a b a 1 x y z String[] args args public static long gcd(long x, long y) {
        if (x < y) {
            return gcd(y, x);
        }

        return x % y == 0 ? y : gcd(y, x % y);
    } gcd {
        if (x < y) {
            return gcd(y, x);
        }

        return x % y == 0 ? y : gcd(y, x % y);
    } if (x < y) {
            return gcd(y, x);
        } x < y x y {
            return gcd(y, x);
        } return gcd(y, x); gcd(y, x) gcd y x return x % y == 0 ? y : gcd(y, x % y); x % y == 0 ? y : gcd(y, x % y) x % y == 0 x % y x y 0 y gcd(y, x % y) gcd y x % y x y long x x long y y public static long div(long x, long y) {
        return x % y == 0 ? x / y : x / y + 1;
    } div {
        return x % y == 0 ? x / y : x / y + 1;
    } return x % y == 0 ? x / y : x / y + 1; x % y == 0 ? x / y : x / y + 1 x % y == 0 x % y x y 0 x / y x y x / y + 1 x / y x y 1 long x x long y y public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        long a = stdin.nextLong();
        long b = stdin.nextLong();
        long c = stdin.nextLong();
        long d = stdin.nextLong();

        // e: cとdの最小公倍数
        long e = (c * d) / gcd(c, d);

        // x: cで割り切れるもの
        // y: dで割り切れるもの
        // z: cでもdでも割り切れるもの
        long x = ((b / c * c) - (div(a, c) * c)) / c + 1;
        long y = ((b / d * d) - (div(a, d) * d)) / d + 1;
        long z = ((b / e * e) - (div(a, e) * e)) / e + 1;
        System.out.println((b - a + 1) - x - y + z);
    }

    public static long gcd(long x, long y) {
        if (x < y) {
            return gcd(y, x);
        }

        return x % y == 0 ? y : gcd(y, x % y);
    }

    public static long div(long x, long y) {
        return x % y == 0 ? x / y : x / y + 1;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        long a = stdin.nextLong();
        long b = stdin.nextLong();
        long c = stdin.nextLong();
        long d = stdin.nextLong();

        // e: cとdの最小公倍数
        long e = (c * d) / gcd(c, d);

        // x: cで割り切れるもの
        // y: dで割り切れるもの
        // z: cでもdでも割り切れるもの
        long x = ((b / c * c) - (div(a, c) * c)) / c + 1;
        long y = ((b / d * d) - (div(a, d) * d)) / d + 1;
        long z = ((b / e * e) - (div(a, e) * e)) / e + 1;
        System.out.println((b - a + 1) - x - y + z);
    }

    public static long gcd(long x, long y) {
        if (x < y) {
            return gcd(y, x);
        }

        return x % y == 0 ? y : gcd(y, x % y);
    }

    public static long div(long x, long y) {
        return x % y == 0 ? x / y : x / y + 1;
    }
} Main
// package c;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdin = new Scanner(System.in);
        long a = stdin.nextLong();
        long b = stdin.nextLong();
        long c = stdin.nextLong();
        long d = stdin.nextLong();

        // e: cとdの最小公倍数
        long e = (c * d) / gcd(c, d);

        // x: cで割り切れるもの
        // y: dで割り切れるもの
        // z: cでもdでも割り切れるもの
        long x = ((b / c * c) - (div(a, c) * c)) / c + 1;
        long y = ((b / d * d) - (div(a, d) * d)) / d + 1;
        long z = ((b / e * e) - (div(a, e) * e)) / e + 1;
        System.out.println((b - a + 1) - x - y + z);
    }

    public static long gcd(long x, long y) {
        if (x < y) {
            return gcd(y, x);
        }

        return x % y == 0 ? y : gcd(y, x % y);
    }

    public static long div(long x, long y) {
        return x % y == 0 ? x / y : x / y + 1;
    }
}