main :: IO ()
main = do
  [a,b,c,d] <- map (read :: String -> Int) . words <$> getLine
  print $ (ans b c d) - (ans (a-1) c d)

ans :: Int -> Int -> Int -> Int
ans n c d = n - div n c - div n d + div n (lcm c d)