← Divide & Conquer

Micro-Drill #81 — Power (fast exponentiation)

Divide & Conquer Target: 15s

Binary exponentiation computes x^n in O(log n). Essential for modular arithmetic problems.

res = 1
while exp:
    if exp & 1:
        res *= base
    base *= base
    exp >>= 1

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #80 Micro #82 →