import java.util.Scanner;

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

        final long a = scanner.nextLong();
        final long b = scanner.nextLong();
        final long c = scanner.nextLong();
        final long d = scanner.nextLong();

        final long gcdVal = gcd(c, d);
        final long cd = c * d / gcdVal;

        System.out.println(b - b / c - b / d + b / cd - (a - 1) + (a - 1) / c + (a - 1) / d - (a - 1) / cd);
    }

    private static long gcd(long a, long b) {
        if (a < b) {
            return gcd(b, a);
        }

        if (b == 0) return a;

        return gcd(b, a % b);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);

        final long a = scanner.nextLong();
        final long b = scanner.nextLong();
        final long c = scanner.nextLong();
        final long d = scanner.nextLong();

        final long gcdVal = gcd(c, d);
        final long cd = c * d / gcdVal;

        System.out.println(b - b / c - b / d + b / cd - (a - 1) + (a - 1) / c + (a - 1) / d - (a - 1) / cd);
    }

    private static long gcd(long a, long b) {
        if (a < b) {
            return gcd(b, a);
        }

        if (b == 0) return a;

        return gcd(b, a % b);
    }
} Main public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);

        final long a = scanner.nextLong();
        final long b = scanner.nextLong();
        final long c = scanner.nextLong();
        final long d = scanner.nextLong();

        final long gcdVal = gcd(c, d);
        final long cd = c * d / gcdVal;

        System.out.println(b - b / c - b / d + b / cd - (a - 1) + (a - 1) / c + (a - 1) / d - (a - 1) / cd);
    } main {
        final Scanner scanner = new Scanner(System.in);

        final long a = scanner.nextLong();
        final long b = scanner.nextLong();
        final long c = scanner.nextLong();
        final long d = scanner.nextLong();

        final long gcdVal = gcd(c, d);
        final long cd = c * d / gcdVal;

        System.out.println(b - b / c - b / d + b / cd - (a - 1) + (a - 1) / c + (a - 1) / d - (a - 1) / cd);
    } final Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) final long a = scanner.nextLong(); a scanner.nextLong() scanner.nextLong scanner final long b = scanner.nextLong(); b scanner.nextLong() scanner.nextLong scanner final long c = scanner.nextLong(); c scanner.nextLong() scanner.nextLong scanner final long d = scanner.nextLong(); d scanner.nextLong() scanner.nextLong scanner final long gcdVal = gcd(c, d); gcdVal gcd(c, d) gcd c d final long cd = c * d / gcdVal; cd c * d / gcdVal c * d c d gcdVal System.out.println(b - b / c - b / d + b / cd - (a - 1) + (a - 1) / c + (a - 1) / d - (a - 1) / cd) System.out.println System.out System System.out b - b / c - b / d + b / cd - (a - 1) + (a - 1) / c + (a - 1) / d - (a - 1) / cd b - b / c - b / d + b / cd - (a - 1) + (a - 1) / c + (a - 1) / d b - b / c - b / d + b / cd - (a - 1) + (a - 1) / c + (a - 1) / d b - b / c - b / d + b / cd - (a - 1) b - b / c - b / d + b / cd b - b / c - b / d b - b / c - b / d b b / c b c b / d b d b / cd b cd (a - 1) a 1 (a - 1) / c (a - 1) a 1 c (a - 1) / d (a - 1) a 1 d (a - 1) / cd (a - 1) a 1 cd String[] args args private 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);
        } 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 class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);

        final long a = scanner.nextLong();
        final long b = scanner.nextLong();
        final long c = scanner.nextLong();
        final long d = scanner.nextLong();

        final long gcdVal = gcd(c, d);
        final long cd = c * d / gcdVal;

        System.out.println(b - b / c - b / d + b / cd - (a - 1) + (a - 1) / c + (a - 1) / d - (a - 1) / cd);
    }

    private 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 class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);

        final long a = scanner.nextLong();
        final long b = scanner.nextLong();
        final long c = scanner.nextLong();
        final long d = scanner.nextLong();

        final long gcdVal = gcd(c, d);
        final long cd = c * d / gcdVal;

        System.out.println(b - b / c - b / d + b / cd - (a - 1) + (a - 1) / c + (a - 1) / d - (a - 1) / cd);
    }

    private static long gcd(long a, long b) {
        if (a < b) {
            return gcd(b, a);
        }

        if (b == 0) return a;

        return gcd(b, a % b);
    }
} Main
import java.util.Scanner;

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

        final long a = scanner.nextLong();
        final long b = scanner.nextLong();
        final long c = scanner.nextLong();
        final long d = scanner.nextLong();

        final long gcdVal = gcd(c, d);
        final long cd = c * d / gcdVal;

        System.out.println(b - b / c - b / d + b / cd - (a - 1) + (a - 1) / c + (a - 1) / d - (a - 1) / cd);
    }

    private static long gcd(long a, long b) {
        if (a < b) {
            return gcd(b, a);
        }

        if (b == 0) return a;

        return gcd(b, a % b);
    }
}