program anti_division
  implicit none
  integer(8) :: a, b, c, d, mc, md, mcd, l
  read(*,*) a, b, c, d
  mc = b/c-(a-1_8)/c
  md = b/d-(a-1_8)/d
  l = c*d/gcd(c,d)
  mcd = b/l-(a-1_8)/l
  write(*,'(i0)') b-a+1-mc-md+mcd
  stop
contains
  recursive function gcd(x,y) result(z)
    implicit none
    integer(8), intent(in) :: x,y
    integer(8) :: z
    if (x.lt.y) then
      z = gcd(y,x)
      return
    end if
    z = x
    if (y.eq.0_8) return
    z = gcd(y,mod(x,y))
    return
  end function gcd
end program anti_division