chickadee » math » modular-expt

modular-expt a b nprocedure
a
integer
b
integer
n
integer

Computes (modulo (expt a b) n), but much more efficiently. The modulus n must be positive, and the exponent b must be nonnegative.

> (modulo (expt -6 523) 19)
13
> (modular-expt -6 523 19)
13
> (modular-expt 9 158235208 19)
4
> ; don't try this at home!
  (modulo (expt 9 158235208) 19)
4