Homework: GCD + Power
作业: 最大公约数 + 幂
Euclid's algorithm (300 BCE) + recursive power. Two short recursions in one file.
Euclid's GCD
Python · runnable
Trace gcd(48, 18)
gcd(48, 18) → gcd(18, 12)
gcd(18, 12) → gcd(12, 6)
gcd(12, 6) → gcd( 6, 0)
gcd( 6, 0) → 6 ← base b shrinks toward 0 each call (because a % b < b), so termination is guaranteed.
Recursive power
Python · runnable
Acceptance criteria
- All 9 tests pass
- Both
gcdandpowerare recursive - No loops / no
**/ nomath.gcd/ nomath.pow