toy-lib-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Math.PowMod

Description

\(\mathit{base}^n \bmod x\) in a constant time using Fermet's little theorem.

TODO: Test all the functions.

Synopsis

Documentation

addMod :: Int -> Int -> Int -> Int #

\(O(1)\)

subMod :: Int -> Int -> Int -> Int #

\(O(1)\)

mulMod :: Int -> Int -> Int -> Int #

\(O(1)\)

factMod :: Int -> Int -> Int #

\(O(N)\) Naive calculation.

powModConst :: Int -> Int -> Int -> Int #

\(O(W)\) \(\mathit{base} ^ \mathit{power} \bmod \mathit{modulo}\) using binary lifting.

invModConst :: Int -> Int -> Int #

\(O(W)\) \(x / d \bmod p\) using Fermat's little theorem and binary lifting.

divModConst :: Int -> Int -> Int -> Int #

\(O(W)\) \(x / d \bmod p\) using Fermat's little theorem and binary lifting.

factModsN :: Int -> Int -> Vector Int #

\(O(N)\) Cache of \(n! \bmod m\) up to n.

bcMod :: Int -> Int -> Int -> Int #

\(O(N)\) nCr mod m (binominal cofficient).