(n, mod=None)
return result
Calculates factorial recursively.
    If mod is not None, then return (n! % mod)
    Time Complexity - O(n)
Calculates factorial recursively.
    If mod is not None, then return (n! % mod)
    Time Complexity - O(n)
Calculates factorial recursively . If mod is not None then return ( n! % mod ) Time Complexity - O ( n )
def factorial_recur(n, mod=None):
    """Calculates factorial recursively.
    If mod is not None, then return (n! % mod)
    Time Complexity - O(n)"""
    if not (isinstance(n, int) and n >= 0):
        raise ValueError("'n' must be a non-negative integer.")
    if mod is not None and not (isinstance(mod, int) and mod > 0):
        raise ValueError("'mod' must be a positive integer")
    if n == 0:
        return 1
    result = n * factorial(n - 1, mod)
    if mod:
        result %= mod
    return result
def factorial_recur ( n , mod = None ) : if not ( isinstance ( n , int ) and n >= 0 ) : raise ValueError ( "'n' must be a non-negative integer." ) if mod is not None and not ( isinstance ( mod , int ) and mod > 0 ) : raise ValueError ( "'mod' must be a positive integer" ) if n == 0 : return 1 result = n * factorial ( n - 1 , mod ) if mod : result %= mod return result