import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int g = C > D ? gcd(C, D) : gcd(D, C);
        long k = (long) C*D/g;
        long result = B - (B/C + B/D - B/k) - (A-1 - ((A-1)/C + (A-1)/D - (A-1)/k));
        System.out.println(result);
    }

    private static int gcd(int a, int b) {
        int temp = 0;
        while (a % b != 0) {
            temp = a;
            a = b;
            b = temp % b;
        }
        return b;
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int g = C > D ? gcd(C, D) : gcd(D, C);
        long k = (long) C*D/g;
        long result = B - (B/C + B/D - B/k) - (A-1 - ((A-1)/C + (A-1)/D - (A-1)/k));
        System.out.println(result);
    }

    private static int gcd(int a, int b) {
        int temp = 0;
        while (a % b != 0) {
            temp = a;
            a = b;
            b = temp % b;
        }
        return b;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int g = C > D ? gcd(C, D) : gcd(D, C);
        long k = (long) C*D/g;
        long result = B - (B/C + B/D - B/k) - (A-1 - ((A-1)/C + (A-1)/D - (A-1)/k));
        System.out.println(result);
    } main {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int g = C > D ? gcd(C, D) : gcd(D, C);
        long k = (long) C*D/g;
        long result = B - (B/C + B/D - B/k) - (A-1 - ((A-1)/C + (A-1)/D - (A-1)/k));
        System.out.println(result);
    } 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 int C = sc.nextInt(); C sc.nextInt() sc.nextInt sc int D = sc.nextInt(); D sc.nextInt() sc.nextInt sc int g = C > D ? gcd(C, D) : gcd(D, C); g C > D ? gcd(C, D) : gcd(D, C) C > D C D gcd(C, D) gcd C D gcd(D, C) gcd D C long k = (long) C*D/g; k (long) C*D/g (long) C*D (long) C D g long result = B - (B/C + B/D - B/k) - (A-1 - ((A-1)/C + (A-1)/D - (A-1)/k)); result B - (B/C + B/D - B/k) - (A-1 - ((A-1)/C + (A-1)/D - (A-1)/k)) B - (B/C + B/D - B/k) - (A-1 - ((A-1)/C + (A-1)/D - (A-1)/k)) B (B/C + B/D - B/k) B/C + B/D B/C B C B/D B D B/k B k (A-1 - ((A-1)/C + (A-1)/D - (A-1)/k)) A-1 - ((A-1)/C + (A-1)/D - (A-1)/k) A 1 ((A-1)/C + (A-1)/D - (A-1)/k) (A-1)/C + (A-1)/D (A-1)/C (A-1) A 1 C (A-1)/D (A-1) A 1 D (A-1)/k (A-1) A 1 k System.out.println(result) System.out.println System.out System System.out result String[] args args private static int gcd(int a, int b) {
        int temp = 0;
        while (a % b != 0) {
            temp = a;
            a = b;
            b = temp % b;
        }
        return b;
    } gcd {
        int temp = 0;
        while (a % b != 0) {
            temp = a;
            a = b;
            b = temp % b;
        }
        return b;
    } int temp = 0; temp 0 while (a % b != 0) {
            temp = a;
            a = b;
            b = temp % b;
        } a % b != 0 a % b a b 0 {
            temp = a;
            a = b;
            b = temp % b;
        } temp = a temp a a = b a b b = temp % b b temp % b temp b return b; b int a a int b b
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        int C = sc.nextInt();
        int D = sc.nextInt();
        int g = C > D ? gcd(C, D) : gcd(D, C);
        long k = (long) C*D/g;
        long result = B - (B/C + B/D - B/k) - (A-1 - ((A-1)/C + (A-1)/D - (A-1)/k));
        System.out.println(result);
    }

    private static int gcd(int a, int b) {
        int temp = 0;
        while (a % b != 0) {
            temp = a;
            a = b;
            b = temp % b;
        }
        return b;
    }
}