import java.util.Scanner;

public class Main {

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

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();
        final long L = lcm(C, D);
        System.out.println((B - B / C - B / D + B / L) - ((A-1) - (A-1) / C - (A-1) / D + (A-1) / L));
    }

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

    private static long gcd(long a, long b) {
        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) {
        Scanner sc = new Scanner(System.in);

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();
        final long L = lcm(C, D);
        System.out.println((B - B / C - B / D + B / L) - ((A-1) - (A-1) / C - (A-1) / D + (A-1) / L));
    }

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

    private static long gcd(long a, long b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();
        final long L = lcm(C, D);
        System.out.println((B - B / C - B / D + B / L) - ((A-1) - (A-1) / C - (A-1) / D + (A-1) / L));
    } main {
        Scanner sc = new Scanner(System.in);

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();
        final long L = lcm(C, D);
        System.out.println((B - B / C - B / D + B / L) - ((A-1) - (A-1) / C - (A-1) / D + (A-1) / L));
    } Scanner sc = new Scanner(System.in); sc new 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 final long L = lcm(C, D); L lcm(C, D) lcm C D System.out.println((B - B / C - B / D + B / L) - ((A-1) - (A-1) / C - (A-1) / D + (A-1) / L)) System.out.println System.out System System.out (B - B / C - B / D + B / L) - ((A-1) - (A-1) / C - (A-1) / D + (A-1) / L) (B - B / C - B / D + B / L) B - B / C - B / D B - B / C - B / D B B / C B C B / D B D B / L B L ((A-1) - (A-1) / C - (A-1) / D + (A-1) / L) (A-1) - (A-1) / C - (A-1) / D (A-1) - (A-1) / C - (A-1) / D (A-1) A 1 (A-1) / C (A-1) A 1 C (A-1) / D (A-1) A 1 D (A-1) / L (A-1) A 1 L String[] args args private 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 private 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 public class Main {

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

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();
        final long L = lcm(C, D);
        System.out.println((B - B / C - B / D + B / L) - ((A-1) - (A-1) / C - (A-1) / D + (A-1) / L));
    }

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

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

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

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();
        final long L = lcm(C, D);
        System.out.println((B - B / C - B / D + B / L) - ((A-1) - (A-1) / C - (A-1) / D + (A-1) / L));
    }

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

    private static long gcd(long a, long b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }
} Main
import java.util.Scanner;

public class Main {

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

        final long A = sc.nextLong();
        final long B = sc.nextLong();
        final long C = sc.nextLong();
        final long D = sc.nextLong();
        final long L = lcm(C, D);
        System.out.println((B - B / C - B / D + B / L) - ((A-1) - (A-1) / C - (A-1) / D + (A-1) / L));
    }

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

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