public void FastPowTest() { Mint m = 2; var x = Mint.Pow(m, 4); Assert.AreEqual(16, x); }
/// <summary> /// nが大きくてkが小さいときに使える。 /// (n <= 1e9, k <= 1e7) /// </summary> /// <param name="n"></param> /// <param name="k"></param> /// <returns></returns> public static Mint nCkForBigNSmallK(long n, long k) { Mint x = 1; Mint y = 1; for (int i = 0; i < k; i++) { x *= n - i; y *= i + 1; } return(x / y); }
private static void Init() { mFactorial = new Mint[SIZE]; mFactrialInverse = new Mint[SIZE]; mInverse = new Mint[SIZE]; mFactorial[0] = mFactorial[1] = 1; mFactrialInverse[0] = mFactrialInverse[1] = 1; mInverse[1] = 1; for (int i = 2; i < SIZE; i++) { mFactorial[i] = mFactorial[i - 1] * i; mInverse[i] = -1 * mInverse[Mint.MOD % i] * (Mint.MOD / i); mFactrialInverse[i] = mFactrialInverse[i - 1] * mInverse[i]; } }