func gcd(_ a: Int, _ b: Int) -> Int {
  if b == 0 {
    return a
  }
  return gcd(b, a % b)
}

let input = readLine()!.split(separator: " ").map { Int($0)! }
let a = input[0] - 1
let b = input[1]
let c = input[2]
let d = input[3]

let lcm = c * d / gcd(c, d)

let canDivides = b / c - a / c + b / d - a / d - (b / (lcm) - a / (lcm))
print(b - a - canDivides)