import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            long A = in.nextLong();
            long B = in.nextLong();
            long C = in.nextLong();
            long D = in.nextLong();
            System.out.println(count(B, C, D) - count(A - 1, C, D));
        }
    }

    private static long count(long N, long C, long D) {
        long countC = N / C;
        long countD = N / D;
        long countCandD = N / (C * D / gcd(C, D));
        return N - countC - countD + countCandD;
    }

    public static final 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) {
        try (Scanner in = new Scanner(System.in)) {
            long A = in.nextLong();
            long B = in.nextLong();
            long C = in.nextLong();
            long D = in.nextLong();
            System.out.println(count(B, C, D) - count(A - 1, C, D));
        }
    }

    private static long count(long N, long C, long D) {
        long countC = N / C;
        long countD = N / D;
        long countCandD = N / (C * D / gcd(C, D));
        return N - countC - countD + countCandD;
    }

    public static final long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
} Main public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            long A = in.nextLong();
            long B = in.nextLong();
            long C = in.nextLong();
            long D = in.nextLong();
            System.out.println(count(B, C, D) - count(A - 1, C, D));
        }
    } main {
        try (Scanner in = new Scanner(System.in)) {
            long A = in.nextLong();
            long B = in.nextLong();
            long C = in.nextLong();
            long D = in.nextLong();
            System.out.println(count(B, C, D) - count(A - 1, C, D));
        }
    } try (Scanner in = new Scanner(System.in)) {
            long A = in.nextLong();
            long B = in.nextLong();
            long C = in.nextLong();
            long D = in.nextLong();
            System.out.println(count(B, C, D) - count(A - 1, C, D));
        } {
            long A = in.nextLong();
            long B = in.nextLong();
            long C = in.nextLong();
            long D = in.nextLong();
            System.out.println(count(B, C, D) - count(A - 1, C, D));
        } Scanner in = new Scanner(System.in) Scanner in = new Scanner(System.in) new Scanner(System.in) long A = in.nextLong(); A in.nextLong() in.nextLong in long B = in.nextLong(); B in.nextLong() in.nextLong in long C = in.nextLong(); C in.nextLong() in.nextLong in long D = in.nextLong(); D in.nextLong() in.nextLong in System.out.println(count(B, C, D) - count(A - 1, C, D)) System.out.println System.out System System.out count(B, C, D) - count(A - 1, C, D) count(B, C, D) count B C D count(A - 1, C, D) count A - 1 A 1 C D String[] args args private static long count(long N, long C, long D) {
        long countC = N / C;
        long countD = N / D;
        long countCandD = N / (C * D / gcd(C, D));
        return N - countC - countD + countCandD;
    } count {
        long countC = N / C;
        long countD = N / D;
        long countCandD = N / (C * D / gcd(C, D));
        return N - countC - countD + countCandD;
    } long countC = N / C; countC N / C N C long countD = N / D; countD N / D N D long countCandD = N / (C * D / gcd(C, D)); countCandD N / (C * D / gcd(C, D)) N (C * D / gcd(C, D)) C * D C D gcd(C, D) gcd C D return N - countC - countD + countCandD; N - countC - countD + countCandD N - countC - countD N - countC - countD N countC countD countCandD long N N long C C long D D public static final 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;
        } 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) {
        try (Scanner in = new Scanner(System.in)) {
            long A = in.nextLong();
            long B = in.nextLong();
            long C = in.nextLong();
            long D = in.nextLong();
            System.out.println(count(B, C, D) - count(A - 1, C, D));
        }
    }

    private static long count(long N, long C, long D) {
        long countC = N / C;
        long countD = N / D;
        long countCandD = N / (C * D / gcd(C, D));
        return N - countC - countD + countCandD;
    }

    public static final 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) {
        try (Scanner in = new Scanner(System.in)) {
            long A = in.nextLong();
            long B = in.nextLong();
            long C = in.nextLong();
            long D = in.nextLong();
            System.out.println(count(B, C, D) - count(A - 1, C, D));
        }
    }

    private static long count(long N, long C, long D) {
        long countC = N / C;
        long countD = N / D;
        long countCandD = N / (C * D / gcd(C, D));
        return N - countC - countD + countCandD;
    }

    public static final 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) {
        try (Scanner in = new Scanner(System.in)) {
            long A = in.nextLong();
            long B = in.nextLong();
            long C = in.nextLong();
            long D = in.nextLong();
            System.out.println(count(B, C, D) - count(A - 1, C, D));
        }
    }

    private static long count(long N, long C, long D) {
        long countC = N / C;
        long countD = N / D;
        long countCandD = N / (C * D / gcd(C, D));
        return N - countC - countD + countCandD;
    }

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