"""Math utilities.""" def factorial(n: int) -> int: """Return n! for a non-negative integer n. Raises TypeError if n is not an int (bool is rejected), ValueError if n < 0. """ if isinstance(n, bool) or not isinstance(n, int): raise TypeError(f"n must be an int, got {type(n).__name__}") if n < 0: raise ValueError(f"n must be >= 0, got {n}") result = 1 for i in range(2, n + 1): result *= i return result