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

lcm = C.lcm(D)

# Bまで
bc = B/C
bd = B/D
blcm = B/lcm

ans_b = B - (bc+bd-blcm)

# Aまで
ac = (A-1)/C
ad = (A-1)/D
alcm = (A-1)/lcm

ans_a = (A-1) - (ac+ad-alcm)

# B - A
puts ans_b - ans_a