A, B, C, D = gets.split.map(&:to_i)

cd_lcm = C.lcm(D)

before_a = A - 1

to_a = before_a - (before_a / C + before_a / D - before_a / cd_lcm)
to_b = B - (B / C + B / D - B / cd_lcm)

puts to_b - to_a
