In competitive programming, you often need to compute where is huge (like ).
Naive exponentiation would overflow. Even has 300+ digits. But using modular arithmetic, you can keep numbers small while computing the correct result modulo .
The trick: . Apply this after every multiplication to prevent overflow.