func gcd(x: Int, _ y: Int) -> Int {
    if y == 0 {
        return x
    } else {
        return gcd(y, x%y)
    }
}
let input = readLine()!.characters.split(" ").map{Int(String($0))!}
let (A, B, C, D) = (input[0]-1, input[1], input[2], input[3])
let tmp = C*D / gcd(C, D)
let tmp1 = B/C - A/C            // (A...B)でCで割り切れる数の個数
let tmp2 = B/D - A/D            // (A...B)でDで割り切れる数の個数
let tmp3 = B/tmp - A/tmp        // (A...B)で(C AND D)で割り切れる数の個数
let tmp4 = tmp1 + tmp2 - tmp3   // (A...B)で(C XOR D)で割り切れる数の個数
print(B - A - tmp4)             // (A...B)で(C AND D)で割り切れない数