Calculates factorial recursively.
    If mod is not None, then return (n! % mod)
    Time Complexity - O(n)
186183
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
988637
function factorial(n) {
  const start = n === 0 ? 1 : Math.abs(n)
  return start > MAX_FACTORIAL
    ? Infinity
    : _.chain(_.range(start, 1))
        .reduce((x, y) => x * y)
        .value()
}
188354
def binomial(n,k):
    
    if n==k: return 1
    assert n>k, "Attempting to call binomial(%d,%d)" % (n,k)
    return factorial(n)//(factorial(k)*factorial(n-k))
254957
def toOrdinal(n):
    
    if n == -1:
        retval = _("last")
    elif n == -2:
        retval = _("penultimate")
    elif 1 <= n <= 5:
        retval = _n2w(n, to="ordinal")
    else:
        retval = _n2w(n, to="ordinal_num")
    return retval
1265343
private static int mod(int a, final int B) {
        final int N = a / B;

        a -= N * B;
        if (a < 0) {
            return a + B;
        }
        return a;
    }
1087448
def factorization( n ):
  """"""

  assert isinstance( n, integer_types )

  if n < 2: return []

  result = []
  d = 2

  # Test the small primes:

  for d in smallprimes:
    if d > n: break
    q, r = divmod( n, d )
    if r == 0:
      count = 1
      while d <= n:
        n = q
        q, r = divmod( n, d )
        if r != 0: break
        count = count + 1
      result.append( ( d, count ) )

  # If n is still greater than the last of our small primes,
  # it may require further work:

  if n > smallprimes[-1]:
    if is_prime( n ):   # If what's left is prime, it's easy:
      result.append( ( n, 1 ) )
    else:               # Ugh. Search stupidly for a divisor:
      d = smallprimes[-1]
      while 1:
        d = d + 2               # Try the next divisor.
        q, r = divmod( n, d )
        if q < d: break         # n < d*d means we're done, n = 1 or prime.
        if r == 0:              # d divides n. How many times?
          count = 1
          n = q
          while d <= n:                 # As long as d might still divide n,
            q, r = divmod( n, d )       # see if it does.
            if r != 0: break
            n = q                       # It does. Reduce n, increase count.
            count = count + 1
          result.append( ( d, count ) )
      if n > 1: result.append( ( n, 1 ) )

  return result
545405
def _nbOperations(n):
    
    if n < 2:
        return 0
    else:
        n0 = (n + 2) // 3
        n02 = n0 + n // 3
        return 3 * (n02) + n0 + _nbOperations(n02)
414894
function binomcoef( n, k ) {
	var res, j;

	if ( isInteger( n ) && isInteger( k ) ) {
		if ( n < 0 ) {
			res = binomcoef( -n + k - 1, k );
			if ( isodd( k ) ) {
				res = -res;
			}
			return res;
		}
		if( n < k ) {
			return 0;
		}
		if ( n - k < k ) {
			k = n - k;
		}
		if (k <	 0) {
			return 0;
		} else if (k === 0) {
			return 1;
		} else {
			// use recursive definition
			res = n;
			for( j = 2; j <= k; j++ ) {
				res *= ( n - j + 1 ) / j;
			}
			// correct for rounding errors
			return !isInteger( res ) ? round( res ) : res;
		}
	} else {
		// generalized version for real numbers
		res = - ln( n + 1 ) - betaln( n - k + 1, k + 1 );
		return exp( res );
	}
}
759169
def carmichael() -> Iterator[int]:
    
    for m in composite():
        for a in range(2, m):
            if pow(a, m, m) != a:
                break
        else:
            yield m
694894
def modInv(a, m):
    """"""
    # notice that a and m need to co-prime to each other.
    if coPrime([a, m]):
        linearCombination = extendedEuclid(a, m)
        return linearCombination[1] % m
    else:
        return 0
805362
private static BigInteger getFactorial(int number) {
                BigInteger factorial = BigInteger.ONE;
                for (int i = number; i > 1; i--) {
                        factorial = factorial.multiply(new BigInteger(Integer.toString(i)));
                }
                return factorial;
        }
894523
def get_factors(n):
    

    def factor(n, i, combi, res):
        """[summary]
        helper function

        Arguments:
            n {[int]} -- [number]
            i {[int]} -- [to tested divisor]
            combi {[list]} -- [catch divisors]
            res {[list]} -- [all factors of the number n]
        
        Returns:
            [list] -- [res]
        """

        while i * i <= n:
            if n % i == 0:
                res += combi + [i, int(n/i)],
                factor(n/i, i, combi+[i], res)
            i += 1
        return res
    return factor(n, 2, [], [])
510727
def _round_to_next_multiple(n, m):
    
    return n if n % m == 0 else n + m - n % m
460403
private final int m() {
		int n = 0;
		int i = k0;
		while (true) {
			if (i > j)
				return n;
			if (!cons(i))
				break;
			i++;
		}
		i++;
		while (true) {
			while (true) {
				if (i > j)
					return n;
				if (cons(i))
					break;
				i++;
			}
			i++;
			n++;
			while (true) {
				if (i > j)
					return n;
				if (!cons(i))
					break;
				i++;
			}
			i++;
		}
	}
515943
def _modulo(self, decimal_argument):
        
        _times, remainder = self._context.divmod(decimal_argument, 100)

        # match the builtin % behavior by adding the N to the result if negative
        return remainder if remainder >= 0 else remainder + 100
1342044
def power(n, m)
      result = 1
      v = n
      while m > 0
        result = mod result * v if m.odd?
        v = square v
        m >>= 1
      end
      result
    end
660145
def estimate_complexity(self, x,y,z,n):
        
        num_calculations = x * y * z * n
        run_time = num_calculations / 100000  # a 2014 PC does about 100k calcs in a second (guess based on prior logs)
        return self.show_time_as_short_string(run_time)