Fast Exponentiation
Square the base once per bit of the exponent, and multiply in on every 1 bit.
Number Theory Basics: 3 to the 13, mod 7
This bit is 1, so multiply the current power in: 1 x 3 mod 7 = 3.
Cost
- Best
- O(log e)
- Average
- O(log e)
- Worst
- O(log e)
- Space
- O(1)
Before this
Related
Leads to
Topics that need this one first.
Taught by the same lesson
Number Theory Basics covers these too, in the same run.