program main
  implicit none
  integer(8) i, A, B, C, D, CD, ans, x1, x2, x3, y1, y2, y3

  read(*, *)A, B, C, D
  x1 = C
  x2 = D
  
  do
    if (x1 < x2) then
      x2 = x2-x1
    elseif (x1 > x2) then
      x1 = x1-x2
    else
      CD = x1
      exit
    end if
  end do
  CD = (C*D)/CD
    
  if (mod(A,C) == 0) then
    x1 = A/C
  else 
    x1 = A/C + 1
  end if
  if (mod(A,D) == 0) then
    x2 = A/D
  else 
    x2 = A/D + 1
  end if
  if (mod(A,CD) == 0) then
    x3 = A/(CD)
  else 
    x3 = A/(CD) + 1
  end if 
  
  if (mod(B,C) == 0) then
    y1 = B/C + 1
  else 
    y1 = B/C + 1
  end if
  if (mod(B,D) == 0) then
    y2 = B/D + 1
  else 
    y2 = B/D + 1
  end if
  if (mod(B,CD) == 0) then
    y3 = B/(CD) + 1
  else 
    y3 = B/(CD) + 1
  end if 

  ans = B-A+1
  ans = ans-(y1-x1)
  ans = ans-(y2-x2)
  ans = ans+(y3-x3)

  write(*,*) ans
end program main
