11.1 Taking modular powers

How do I compute modular powers in Sage?

To compute $ 51^{2006} \pmod{97}$ in Sage, type

sage: R = Integers(97)
sage: a = R(51)
sage: a^2006
12

Instead of R = Integers(97) you can also type R = IntegerModRing(97). Another option is to use the Sage interface with GMP:

sage: 51.powermod(99203843984,97)   
96

See About this document... for information on suggesting changes.