Compute the Factorial of n, often written as <code>c!</code> in
mathematics.

@param n Note: n &gt;= 0
@return n * (n-1) * (n-2) * ... * 1
320779
public static double approximateFactorial(int n) {
    double nFac = 1.0;
    for(int i = n; i > 0; i--) {
      nFac *= i;
    }
    return nFac;
  }
429648
public static double logChoose(int n, int k) {
        if (n < 0 || k < 0 || k > n) {
            throw new IllegalArgumentException(String.format("Invalid n = %d, k = %d", n, k));
        }

        return Math.logFactorial(n) - Math.logFactorial(k) - Math.logFactorial(n - k);
    }
858082
private int rational(int n) {
		while (n >= shapes.size()) {
			n -= shapes.size();
		}
		while (n < 0) {
			n += shapes.size();
		}
		
		return n;
	}
1198033
public static final BigDecimal sqrt(BigDecimal n) {
		if (n.compareTo(BigDecimal.ZERO) <= 0) {
			throw new IllegalArgumentException();
		}

		final BigDecimal TWO = new BigDecimal("2");
		BigDecimal error;
		BigDecimal lastGuess = BigDecimal.ZERO;
		BigDecimal guess = BigDecimal.ONE.movePointRight(n.toBigInteger().toString().length() / 2);
		int maxIterations = 50;
		int iterations = 0;
		boolean more = true;
		while (more) {
			lastGuess = guess;
			guess = n.divide(guess, UJMPSettings.getInstance().getMathContext());
			guess = guess.add(lastGuess);
			guess = guess.divide(TWO, UJMPSettings.getInstance().getMathContext());
			error = n.subtract(guess.multiply(guess));
			if (++iterations >= maxIterations) {
				more = false;
			} else if (lastGuess.equals(guess)) {
				more = error.abs().compareTo(BigDecimal.ONE) >= 0;
			}
		}
		return guess;
	}
818152
public static long factorial(int arg) {
        if (arg <= 0) {
            throw new IllegalArgumentException("参数必须大于0");
        }
        long result = 1;
        for (int i = arg; i > 0; i--) {
            result *= i;
        }

        return result;
    }
494122
public static PermutationMatrix getInstance(int n)
    {
        PermutationMatrix pm = map.get(n);
        if (pm == null)
        {
            pm = new PermutationMatrix(n);
            map.put(n, pm);
        }
        return pm;
    }
869861
public GeometryExpression<Geometry> geometryN(Integer n) {
        return GeometryExpressions.geometryOperation(SpatialOps.GEOMETRYN, mixin, ConstantImpl.create(n));
    }
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))
16690
public static long factoriall(int n) {
        checkNonNegative("n", n);
        return (n < long_factorials.length) ? long_factorials[n] : Long.MAX_VALUE;
    }
534020
public static Matrix3D identity(int N) {
        Matrix3D I = new Matrix3D(N, N, N);
        for (int i = 0; i < N; i++)
            I.data[i][i][i] = 1;
        return I;
    }
1367739
public static int log2 (int n){
    int log = 0;

    for(int k=1; k < n; k *= 2, log++);

    if (n != (1 << log))
      return -1 ; /* n is not a power of 2 */
    return log; }
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
699318
public static int gcd(int m, int n) {
    if (m == 0 && n == 0)
      return 0;
    if (m < n) {
      int t = m;
      m = n;
      n = t;
    }
    int r = m % n;
    if (r == 0) {
      return n;
    } else {
      return gcd(n, r);
    }
  }
654224
def nPr(n, r):
    
    f = math.factorial
    return int(f(n) / f(n-r))
1014845
public static Rational binomial(Rational n, BigInteger m) {
        if (m.compareTo(BigInteger.ZERO) == 0) {
            return Rational.ONE;
        }
        Rational bin = n;
        for (BigInteger i = BigInteger.valueOf(2); i.compareTo(m) != 1; i = i.add(BigInteger.ONE)) {
            bin = bin.multiply(n.subtract(i.subtract(BigInteger.ONE))).divide(i);
        }
        return bin;
    }
1158838
public static String string(double n) {
        if (Double.isInfinite(n)) {
            return (n > 0) ? "+inf" : "-inf";
        }
        return Double.toString(n);
    }
1033392
function factorialOfNumber(number) {
        if (isInteger(number)) {
            var arrayOfNumbers = [];
            while (number >= 1) {
                arrayOfNumbers.push(number);
                number--;
            }
            return this.mul(arrayOfNumbers);
        }
        else {
            return 0;
        }
    }