main = do
  (a:b:x:y) <- (map read) . words <$> getLine
  let z = ((b-a) `div` x ) + ans a b (b-a) x
  print z

ans a b c x =
  let ax = a `mod` x in
    let bx = b `mod` x in
      if a/=b then
        if a==c then
          if bx==0 then
            1
          else
            0
        else if b==c then
          if ax==0 then
            1
          else
            0
        else if ax==0 && bx==0 then
               2
        else if ax==0 || bx==0 then
               1
        else
               0
      else
        if ax==0 then
          1
        else
          0
