n = gets.split.map(&:to_i)
divi = [0,0,0]
divi[0] = (n[1]/n[2])-((n[0]-1)/n[2])
divi[1] = (n[1]/n[3])-((n[0]-1)/n[3])
require 'prime'
prime = []
Prime.each(10**5) do |pr|
  prime.push(pr)
end
mini = 1
for i in 0..prime.length-1
  while n[2] % prime[i] == 0 && n[3] % prime[i] == 0
    n[2] /= prime[i]
    n[3] /= prime[i]
    mini *= prime[i]
  end
end
mini *= n[2]
mini *= n[3]
divi[2] = (n[1]/mini)-((n[0]-1)/mini)
puts (n[1]-n[0]+1) - divi[0] - divi[1] + divi[2]
