Function reference · Math
powmod
Computes base^exponent mod modulus exactly, without computing the full power.
Notation
powmod(base, exponent, modulus)
Write it in an expression: nerdamer('powmod(2,10,7)'), or in the Playground.
nerdamer.powmod
nerdamer.powmod(base: ExpressionInput, exponent: ExpressionInput, modulus: ExpressionInput): Expression
A method on the default import. Arguments can be strings, as in Notation.
Parameters
base- An integer.
exponent- A nonnegative integer.
modulus- A positive integer.
Returns
The remainder, an integer from 0 up to modulus - 1.
Examples
Large exponents are fast, because the full power is never built.
powmod(3,200,13)
// → 9Open in PlaygroundA negative base still gives a remainder from 0 up to modulus - 1.
powmod(-3,3,7)
// → 1Open in PlaygroundGood to know
- A negative exponent or a modulus below 1 is an error.
JavaScript examples
nerdamer.powmod(2, 10, 7).text()
// → 2