require 'set'; require 'prime'
INF=Float::INFINITY
a,b,c,d = gets.chomp.split.map(&:to_i)

cd = c.lcm(d)
a-=1
aa = a -a/c - a/d + a / cd
bb = b -b/c - b/d + b / cd

ans = bb - aa
# ans+= 1 unless a%c==0 and a%d==0
puts ans