local function gcd(a,b)
    if b == 0 then
        return a
    else
        return gcd(b, a % b)
    end
end

local function gcdmany(tbl)
    local ans = tbl[1]
    for i=2,#tbl do
        ans = gcd(ans, tbl[i])
    end
    return ans
end

local function lcm(a, b)
    return a // gcd(a, b) * b
end

local function lcmmany(tbl)
    local ans = tbl[1]
    for i=2, #tbl do
        ans = lcm(ans, tbl[i])
    end
    return ans
end

---
local A, B, C, D = io.read("n", "n", "n", "n")
local function candiv(x)
    return (B // x) - ((A-1) // x)
end
local total = B - A + 1
local c_div = candiv(C)
local d_div = candiv(D)
local cd_lcm = lcm(C, D)
local cd_div = candiv(cd_lcm)
local ans = total - c_div - d_div + cd_div
print(ans)
