A, B, C, D = $stdin.read.chomp.split(" ").map(&:to_i)

res = B - A + 1

cis = (A / C.to_f).ceil
cie = (B / C.to_f).floor
ccount = if cis == 1 && cie == 0
           0
         else
           (cie - cis).abs + 1
         end

dis = (A / D.to_f).ceil
die = (B / D.to_f).floor
dcount = if dis == 1 && die == 0
           0
         else
           (die - dis).abs + 1
         end

_gcd = C.gcd(D)
_cd = C*D/_gcd
cdis = (A / (_cd).to_f).ceil
cdie = (B / (_cd).to_f).floor
cdcount = if cdis == 1 && cdie == 0
            0
          else
            (cdie - cdis).abs + 1
          end

puts res - ccount - dcount + cdcount
