Ranked Panel Selection Report
Context
A reporting team analyzes a pool of ranked nominees and needs to summarize how many distinct panels of a chosen size could be formed. The report displays this count modulo a configured positive base so large values remain manageable. Given the pool size, panel size, and modulus, calculate the requested modular count.
Problem
For a pool of n nominees, a panel of r nominees can be formed in C(n, r) distinct ways. Return C(n, r) modulo modulus. Compute the value using Pascal's recurrence. Begin with the constant coefficient C(0, 0) = 1, then process rows through n. Store only coefficients up to r. When extending each row, update positions from r downward so that every addition uses values from the preceding row rather than values already changed in the current row. Reduce each stored value modulo modulus after adding. The inputs guarantee 0 ≤ r ≤ n and modulus ≥ 1. If modulus is 1, the returned residue is 0.
Examples
modulus = 100n = 5r = 210modulus = 7n = 6r = 36modulus = 13n = 4r = 01Constraints
0 <= n <= 10000 <= r <= n1 <= modulus <= 1000000000- Types:
nis int,ris int,modulusis int; result is int
Function signature
def panel_selection_residue(n: int, r: int, modulus: int) -> int
nint- The total number of nominees.
rint- The number of nominees selected for the panel.
modulusint- The positive base used to reduce the panel count.
- returns int
- The number of distinct r-nominee panels from n nominees, reduced modulo modulus.
Adapted from MBPP problem task_402 (CC BY 4.0). Rewritten, extended and verified by Iksha.