Exercise 1: Square-and-Multiply Trace for 5^9 mod 11 — Possible Solution ==================================================================== GIVEN ------------------------------ a = 5, b = 9, n = 11. 9 in binary is 1001. STEP-BY-STEP TRACE ------------------------------ Start: base = 5 mod 11 = 5, result = 1 Bit 1 (rightmost, value 1): bit is 1 -> result = 1*5 mod 11 = 5 Square base: 5^2 mod 11 = 25 mod 11 = 3 Bit 2: bit is 0 -> no multiply Square base: 3^2 mod 11 = 9 mod 11 = 9 Bit 3: bit is 0 -> no multiply Square base: 9^2 mod 11 = 81 mod 11 = 4 Bit 4 (leftmost, value 1): bit is 1 -> result = 5*4 mod 11 = 20 mod 11 = 9 Square base: 4^2 mod 11 = 16 mod 11 = 5 (this final squaring isn't used further since all 4 bits have now been processed) RESULT ------------------------------ 5^9 mod 11 = 9 Total multiplications: 4 squarings + 2 bit-triggered multiplies (at bit 1 and bit 4) = 6 multiplications total, dramatically fewer than the naive approach's 9. WHY THIS WORKS AS AN ANSWER ------------------------------ Every one of the 4 bits of 9 (1001 in binary) is processed in order, with squaring happening every iteration and the extra multiply happening only when the corresponding bit is 1, matching this chapter's own algorithm exactly - and the final answer matches what Python's own pow(5,9,11) computes.