program sample
    implicit none
    
    integer(8) :: i,j,l,m,n,a,b,c,d,c1,d1,d2
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) a,b,c,d
    m=b/c-(a-1)/c
    n=b/d-(a-1)/d
    c1=max(c,d)
    d1=min(c,d)
    do i=1,10**6
        d2=mod(c1,d1)
        c1=d1
        d1=d2
        if(d1==0)then
            exit
        end if
    end do
    d1=c*d/c1
    l=b/d1-(a-1)/d1
    write(*,*)b-(a-1)-m-n+l


        
    stop
end program sample
  

