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 > Binomial Modulo Small Prime > Editorial

Binomial Modulo Small Prime — Solution & Editorial

Back to the Problem

Lucas' theorem: C(N, K) mod P = ∏ C(Ni, Ki) mod P over the base-P digits of N and K. Each small binomial uses factorials mod P.

Complexity: O(logP N · P)

Watch out: A digit of K exceeding the corresponding digit of N makes the whole product 0 — the core of Lucas.