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 > Square Root Modulo a Prime > Editorial

Square Root Modulo a Prime — Solution & Editorial

Back to the Problem

Check Euler's criterion A(P−1)/2 ≡ 1 for solvability. For P ≡ 3 (mod 4), x = A(P+1)/4; otherwise Tonelli–Shanks.

Complexity: O(log2 P)

Watch out: P ≡ 1 (mod 4) genuinely needs Tonelli–Shanks; the (P+1)/4 shortcut only works for P ≡ 3 (mod 4).