[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let gcd x y =
    let rec aux x y = if y = 0L then x else aux y (x % y)
    aux (abs x) (abs y)

let lcm x y = if x = 0L || y = 0L then 0L else abs ((x / (gcd x y)) * y)

[<EntryPoint>]
let main _ =
    let [a;b;c;d] = reads int64
    let n = b - a + 1L
    let ca = (a + c - 1L) / c
    let cb = b / c
    let da = (a + d - 1L) / d
    let db = b / d
    let e = lcm c d
    let ea = (a + e - 1L) / e
    let eb = b / e

    let cc = cb - ca + 1L
    let dd = db - da + 1L
    let ee = eb - ea + 1L

    printfn "%i" (n - (cc + dd - ee))
    0