def lcm(a,b)
	a/gcd(a,b)*b
end
def gcd(a,b)
	if(a>b)
		return gcd(b,a)
	end
	if(b%a == 0)
		return a
	else
		return gcd(a,b%a)
	end
end
A,B,C,D=gets.chomp.split(' ').map{|n| n.to_i}
qac = A%C == 0 ? A/C : A/C+1
qbc = B%C == 0 ? B/C : B/C
qad = A%D == 0 ? A/D : A/D+1
qbd = B%D == 0 ? B/D : B/D
qacd = A%lcm(C,D) == 0 ? A/lcm(C,D) : A/lcm(C,D)+1
qbcd = B%lcm(C,D) == 0 ? B/lcm(C,D) : B/lcm(C,D)
# puts qac
# puts qbc
# puts qad
# puts qbd
# puts lcm(C,D)
# puts qacd
# puts qbcd
cnt = qbc - qac + 1
cnt += qbd - qad + 1
cnt -= qbcd - qacd + 1
# puts cnt
puts B-A+1-cnt
