implicit none
integer(8) :: a,b,c,d
integer(8) :: nc, nd, ncd, m, n, r
read *,a,b,c,d

nc = b/c - (a-1)/c  ! Numbers that can be divided by C
nd = b/d - (a-1)/d  ! Numbers that can be divided by D

! GCD
if (c > d) then
   m = c
   n = d
else
   m = d
   n = c
endif

r = 1
do while (r > 0)
   r = mod(m,n)
   m = n
   n = r
enddo

! LCM
m = c * d / m

ncd = b/m - (a-1)/m   ! Numbers that can be divided by C & D

write(6,'(i0)') b-a+1 - nc - nd + ncd
stop
end