program dv
  implicit none
  integer(8) :: A,B,C,D,nC,nD,nCD,CD,i

  read(*,*) A,B,C,D
  if(mod(A,C).ne.0) then
     nC=-A/C+B/C
  else
     nC=-A/C+B/C+1
  endif
  if(mod(A,D).ne.0) then
     nD=-A/D+B/D
  else
     nD=-A/D+B/D+1
  endif
  CD=C*D/gcd(C,D)
  if(mod(A,CD).ne.0) then
     nCD=-A/CD+B/CD
  else
     nCD=-A/CD+B/CD+1
  endif
  write(*,'(i0)') B-A+1-nC-nD+nCD
stop
contains
function gcd(x,y) result(z)
  implicit none
  integer(8) :: x,y,z
  integer(8) :: m,n,k
  m=x
  n=y
  do while(.true.)
     k=mod(m,n)
     if(k.eq.0) then
        z=n
        exit
     endif
     m=n
     n=k
  enddo

end function gcd
end program dv