up previous next
PowerMod    --    compute a modular power efficiently


Syntax
PowerMod(A: INT, B: INT, M: INT): INT

Description
This function calculates efficiently an integer power modulo a given modulus. Thus PowerMod(A, B, M) is equal to mod(A^B, M), but the former is computed faster. If A and M are coprime then B may be negative.

Example
/**/  PowerMod(12345,41041,41041); -- 41041 is a Carmichael number
12345

/**/  PowerMod(123456789,987654321,32003); -- cannot compute 123456789^987654321 directly
2332