local a, b = io.read("*n", "*n")
local c, d = io.read("*n", "*n")

local function getgcd(x, y)
  while 0 < x do
    x, y = y % x, x
  end
  return y
end
local function getlcm(x, y)
  local gcd = getgcd(x, y)
  return (x // gcd) * y
end

local cd = getlcm(c, d)

local cnt = b - a + 1
cnt = cnt - (b // c - (a - 1) // c)
cnt = cnt - (b // d - (a - 1) // d)
cnt = cnt + (b // cd - (a - 1) // cd)
print(cnt)
