program ccc

implicit none
integer(8) :: a, b, c, d, cd, a1, a2, a3, one, two, thr, ans

read*, a, b, c, d

call lcm(c,d,cd)

one=mod(a,c)
two=mod(a,d)
thr=mod(a,cd)

a1=a+(c-one)
a2=a+(d-two)
a3=a+(cd-thr)

if(one==0) a1=a
if(two==0) a2=a
if(thr==0) a3=a

if(a1>b) a1=b+c
if(a2>b) a2=b+d
if(a3>b) a3=b+cd

ans=(1+int((b-a1)/c))+(1+int((b-a2)/d))-(1+int((b-a3)/(cd)))

ans=(b-a+1)-ans

!write(*,'(i0)') a1, a2, a3, (1+int((b-a3)/(cd)))
write(*,'(i0)') ans

end program


subroutine lcm(a,b,res)
integer(8) :: aa, bb, a, b, dumy, i, m, res

aa=a
bb=b

if(a<b) then
dumy=a
a=b
b=dumy
end if

do i = 1, 100000
m=mod(a,b)
if (m==0) then
res=aa*bb/b
a=aa
b=bb
return
else
a=b
b=m
end if
end do

end subroutine lcm