program abc131c
  use,intrinsic :: iso_fortran_env
  implicit none
  integer(int64) :: a, b, c, d, x, y
  read *, a, b, c, d
  a = a - 1
  x = a - a/c - a/d + a/lcm(c,d)
  y = b - b/c - b/d + b/lcm(c,d)
  print *, y-x
contains
  recursive function gcd(a,b) result(res)
    integer(int64),intent(in) :: a, b
    integer(int64) :: res
    if (b==0) then
       res = a
    else
       res = gcd(b,mod(a,b))
    end if
  end function gcd
  function lcm(a,b)
    integer(int64),intent(in) :: a, b
    integer(int64) :: lcm
    lcm = a/gcd(a,b)*b
  end function lcm
end program abc131c
