program ccc

implicit none
integer(16) :: a, b, c, d, cd, ans

read*, a, b, c, d
call lcm(c,d,cd)

ans=b-((int(b/c)+int(b/d)-int(b/cd)))
ans=ans-((a-1)-(int((a-1)/c)+int((a-1)/d)-int((a-1)/cd)))

write(*,'(i0)') ans
end program

subroutine lcm(a,b,res)
implicit none
integer(16) :: 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