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

if C<D
  n,m = C,D 
else 
  n,m = D,C
end
while m%n != 0
  n,m = m%n, n
end

lcm = C*D/n

p B - A + 1 - ((B/C)-((A-1)/C)) - ((B/D)-((A-1)/D)) + ((B/lcm)-((A-1)/lcm))