We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class ModularArithmetic(val mod: Long) { class Mod(val value: Long) { override val toString = value.toString } implicit def fromMod(mod: Mod): Long = mod.value implicit def toMod(x: Long): Mod = new Mod(x%mod) val factorial: IndexedSeq[Mod] = { val N = 5500 val f = Array.ofDim[Mod](N) f(0) = 1L (1 until N).foreach(i => f(i) = f(i-1) * i) f } def modularInverse(n: Long): Mod = BigInt(n).modInverse(mod).toLong //If mod is prime override this with BigInt(n).modPow(mod - 2, mod).toLong def modDiv(a: Long, b: Long): Mod = a * modularInverse(b) def permutations(n: Int, k: Int): Mod = modDiv(factorial(n), factorial(n - k)) def combinations(n: Int, k: Int): Mod = modDiv(permutations(n, k), factorial(k)) }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: