Hiring process8 levels
  1. 1 IQ Test
  2. 2 Additional Online Test (If Required)
  3. 3 Office Interview with Hiring Manager
  4. 4 Unpaid Test Task (Motivation Check)
  5. 5 Paid Test Task and Follow-Up Interview
  6. 6 Iterative Paid Test Tasks
  7. 7 Office Verification
  8. 8 Final Interview with the Founder

Problems > Power Tower Modulo > Editorial

Power Tower Modulo — Solution & Editorial

Back to the Problem

Recurse on the exponent modulo φ(M) using Euler's generalized theorem ae ≡ a(e mod φ(m)) + φ(m) (mod m), valid when e ≥ φ(m). Crucially, only add φ when the true tower above actually reaches φ; a short tower must be used exactly.

Complexity: O(K · √M)

Watch out: Do NOT always add φ: when the exponent tower is smaller than φ(m) (e.g. 2^2 mod 1000 = 4), adding φ gives the wrong residue. Test tower height explicitly.