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 > Two Squares > Editorial

Two Squares — Solution & Editorial

Back to the Problem

By Fermat's two-squares theorem, N works iff every prime factor of the form 4k+3 appears to an EVEN power. Factor by trial division to √N (or rho) and check the 4k+3 exponents.

Complexity: O(√N)

Watch out: 0 = 0²+0² is YES; and the leftover prime after the loop needs its own 4k+3 check.