# calculate modular algorithm with large exponents [duplicate]

I don't know how to calculate the following modulo: $$321^{654} \mod 1013$$

Are there some easy way to do this?

## marked as duplicate by Watson, Davide Giraudo, Winther, Jean-Claude Arbaut, JMPSep 26 '16 at 0:15

Working in the prime field $\Bbb F_{1013}$ we can use equalities.
$$321^{654}=(321^{109})^6$$ so from $321^{10}=52$ we have $$321^{100}=52^{10}=781\Rightarrow321^{109}=781\cdot(321)^9=185\cdot1013+35$$ It follows $$321^{654}=35^6=\color{red}{863}$$