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

c_l = b/c
c_s = a%c==0 ? a/c : (a/c+1)
c_sum = c_l - c_s + 1

d_l = b/d
d_s = a%d==0 ? a/d : (a/d+1)
d_sum = d_l - d_s + 1

cd_l = b/c.lcm(d)
cd_s = a%d==0 ? a/c.lcm(d) : (a/c.lcm(d) + 1)
cd_sum = cd_l - cd_s + 1

puts b - a + 1 - (c_sum + d_sum - cd_sum)