a, b, c, d = gets.chomp.split().map(&:to_i)

ac = (a-1) / c
ad = (a-1) / d
bc = b / c
bd = b / d
cd_lcm = c.lcm(d)
acd_lcm = (a-1) / cd_lcm
bcd_lcm = b / cd_lcm

l = b - a + 1

puts l - (bc - ac) - (bd - ad) + (bcd_lcm - acd_lcm)
