require'rational'
a, b, c, d  = gets.split(" ").map(&:to_i)
array = (a..b).to_a
n = array.size

c_sum = 0
d_sum = 0
cd_sum = 0

n.times do |i|
    if array[i]%c == 0
        c_sum = array[i..-1].size/c + (array[i..-1].size%c == 0? 0 : 1)
        break
    end
end

n.times do |i|
    if array[i]%d == 0
        d_sum = array[i..-1].size/d + (array[i..-1].size%d == 0? 0 : 1)
        break
    end
end

min_bi = c.lcm(d)

n.times do |i|
    if array[i]%c == 0 && array[i]%d == 0
        cd_sum = array[i..-1].size/min_bi + (array[i..-1].size%min_bi == 0? 0 : 1)
        break
    end
end

puts array.size - c_sum - d_sum + cd_sum
