Calculates factorial iteratively.
    If mod is not None, then return (n! % mod)
    Time Complexity - O(n)
492175
def factorial(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")
    result = 1
    if n == 0:
        return 1
    for i in range(2, n+1):
        result *= i
        if mod:
            result %= mod
    return result
567485
def _ttr(self, k, dist, cache):
        """"""
        a,b = evaluation.evaluate_recurrence_coefficients(dist, k)
        return -a, b
1090008
public static long count(int n, int m) {
		if(0 == m) {
			return 1;
		}
		if(n == m) {
			return NumberUtil.factorial(n) / NumberUtil.factorial(m);
		}
		return (n > m) ? NumberUtil.factorial(n, n - m) / NumberUtil.factorial(m) : 0;
	}
446617
def number_of_permutations(self):
        
        if self.permutations_safe_override:
            return factorial(self.coordination)
        elif self.permutations is None:
            return factorial(self.coordination)
        return len(self.permutations)
952743
def calculateSleepTime(attempt):
    
    if attempt <= 0:
        return 0

    # We subtract one to get exponents: 1, 2, 3, 4, 5, ..
    delay = float(2 ** (attempt - 1)) * float(DELAY_FACTOR)
    # Apply randomization factor
    delay = delay * (RANDOMIZATION_FACTOR * (random.random() * 2 - 1) + 1)
    # Always limit with a maximum delay
    return min(delay, MAX_DELAY)
375057
def mod_root(a, p):
    
    if a == 0:
        return 0
    if not mod_issquare(a, p):
        raise ValueError
    n = 2
    while mod_issquare(n, p):
        n += 1
    q = p - 1
    r = 0
    while not q.getbit(r):
        r += 1
    q = q >> r
    y = pow(n, q, p)
    h = q >> 1
    b = pow(a, h, p)
    x = (a * b) % p
    b = (b * x) % p
    while b != 1:
        h = (b * b) % p
        m = 1
        while h != 1:
            h = (h * h) % p
            m += 1
        h = gmpy.mpz(0)
        h = h.setbit(r - m - 1)
        t = pow(y, h, p)
        y = (t * t) % p
        r = m
        x = (x * t) % p
        b = (b * y) % p
    return x
1204716
function factorial(n) {
  const start = n === 0 ? 1 : Math.abs(n)
  return start > MAX_FACTORIAL
    ? Infinity
    : Lazy.range(start, 1).reduce((x, y) => x * y)
}
1075994
def get_factors_iterative2(n):
    

    ans, stack, x = [], [], 2
    while True:
        if x > n // x:
            if not stack:
                return ans
            ans.append(stack + [n])
            x = stack.pop()
            n *= x
            x += 1
        elif n % x == 0:
            stack.append(x)
            n //= x
        else:
            x += 1
222659
private int modInverse(int x) {
		// Cube gives inverse mod 2^4, as x^4 == 1 (mod 2^4) for all odd x.
		int inverse = x * x * x;
		// Newton iteration doubles correct bits at each step.
		inverse *= 2 - x * inverse;
		inverse *= 2 - x * inverse;
		inverse *= 2 - x * inverse;
		return inverse;
	}
1027228
public static long factorial(int n) {
    long nFac = 1;
    for(long i = n; i > 0; i--) {
      nFac *= i;
    }
    return nFac;
  }
1033392
function factorialOfNumber(number) {
        if (isInteger(number)) {
            var arrayOfNumbers = [];
            while (number >= 1) {
                arrayOfNumbers.push(number);
                number--;
            }
            return this.mul(arrayOfNumbers);
        }
        else {
            return 0;
        }
    }
569946
function factorize(n, addFactor) {
    let remainder = 0;
    let i = 0;
    let multiplier = FOUND_PRIMES[i];

    //go through prime multipliers
    while (multiplier <= n) {
        do {
            remainder = n % multiplier;
            if (!remainder) {
                n /= multiplier;
                addFactor(multiplier);
            }
        } while (!remainder);
        multiplier = FOUND_PRIMES[++i];
    }
}
275596
def order_mod( x, m ):
  

  # Warning: this implementation is not very clever, and will
  # take a long time if m is very large.

  if m <= 1: return 0

  assert gcd( x, m ) == 1

  z = x
  result = 1
  while z != 1:
    z = ( z * x ) % m
    result = result + 1
  return result
953618
def factorial(n):
    
    f = 1
    while (n > 0):
        f = f * n
        n = n - 1
    return f
66420
private static BigInteger getFactorial (int n) {
		BigInteger fact = BigInteger.ONE;
		for (int i = n; i > 1; i--) {
			fact = fact.multiply (new BigInteger (Integer.toString (i)));
		}
		return fact;
	}
956605
def isqrt(n):
    ''' 
    '''
    # TODO: replace with a more efficient implementation

    if n == 0:
        return n, 1
    if n < 0:
        raise ValueError('math domain error')

    a, b, c = 1, n, 1

    def divisors():
        yield 2
        yield 3
        k = 5
        while k * k <= b:
            yield k
            k += 2
            yield k
            k += 4
            
    for k in divisors():
        d, m = divmod(b, k * k)
        while m == 0:
            a *= k
            b = d
            d, m = divmod(b, k * k)
        if b % k == 0:
            b //= k
            c *= k

        k += 1
    return a, b*c
997869
function( n, multiple ) {
        'use strict';

        var remainder = 0;

        if ( multiple === 0 ) {
            return n;
        }

        remainder = Math.abs( n ) % multiple;

        if ( remainder === 0 ) {
            return n;
        }

        if ( n < 0 ) {
            return -( Math.abs( n ) - remainder );
        }

        return n + multiple - remainder;
    }