Keep the arithmetic contract explicit
Connect totients, huge exponents, congruences, and division-free sums.
Understand the idea
Euler’s totient φ(n) counts values in [1,n] coprime to n and equals n times the product of (1 − 1/p) over distinct prime factors. To process a decimal exponent too large to store, update result = result^10 × base^digit modulo m for each digit.
Trace a small example
φ(12) = 4, corresponding to 1, 5, 7, 11. A geometric sum can be combined alongside a power using doubling identities, without assuming a − 1 has an inverse. Coprime congruences modulo 3 and 5 combine into one residue modulo 15.
Conditions and cost
Euler exponent reduction requires coprimality; decimal digit processing does not. Simple Chinese-remainder formulas require coprime moduli. For larger modulus bounds, ordinary long long multiplication may need an overflow-safe replacement.
When is a^φ(m) congruent to 1 modulo m valid for m > 1?
Turn the idea into code
Find the residue modulo 15 that is 2 modulo 3 and 3 modulo 5.
Give me a hint
Test 3, 8, 13 against modulus 3.
Show the explained solution
8 satisfies both conditions. Coprimality makes the solution unique modulo 15.
Your notes
Mark complete when you can explain it yourself.