program main
implicit none
integer(8) :: a, b, c, d, e, i
integer(8) :: k, l, m, n

read(*,*) a, b, c, d

n = b-a+1
k = 0
l = 0
m = 0

e = c*d/gcd( c, d )
if( mod( b, c ) == 0 .and. mod( a, c) == 0 ) then
   k = b/c -a/c +1
else
   k = b/c - a/c
end if
if( mod( b, d ) == 0 .and. mod( a, d) == 0 ) then
   l = b/d -a/d +1
else
   l = b/d - a/d
end if
if( mod( b, e ) == 0 .and. mod( a, e) == 0 ) then
   m = b/e -a/e +1
else
   m = b/e - a/e
end if
write(*,'(i0)') n - k - l + m
 stop
contains
  integer function gcd(a, b)
    implicit none
    integer(8), intent(IN) :: a, b
    integer(8) :: l, m, n
    m = a
    n = b
    do
      l = mod(m, n)
      if (l == 0) exit
      m = n
      n = l
    end do
    gcd = n
    return
  end function gcd
end program main
