a,b,c,d = gets.chomp.split(' ').map(&:to_i)
c_a = (a-1)/c
d_a = (a-1)/d
c_b = b/c
d_b = b/d
lcm = c.lcm(d)
lcm_a = (a-1)/lcm
lcm_b = b/lcm
puts b - a + 1 - (c_b - c_a ) - (d_b - d_a) + (lcm_b - lcm_a)