Binomial Coefficient Modulo a Prime by Lucas’s Theorem

Compute C(n,k) modulo a prime from the base-prime digits of exact nonnegative decimal integers; the prime is capped at 10,000 for bounded work.

Description

Lucas’s theorem reduces a binomial coefficient modulo a prime to smaller binomial coefficients of base-prime digits.

Lucas’s theorem reduces a binomial coefficient modulo a prime to smaller binomial coefficients of base-prime digits. This allows large indexes without constructing the full binomial coefficient.1

The tool returns residue. The indexing and output conventions below determine how to read these values.

When to use Binomial Coefficient Modulo a Prime by Lucas’s Theorem

Use this for the following task: Compute C(n,k) modulo a prime from the base-prime digits of exact nonnegative decimal integers; the prime is capped at 10,000 for bounded work. Use the input and output conventions below to reproduce the intended mathematical quantity.

How to use Binomial Coefficient Modulo a Prime by Lucas’s Theorem and understand its results

  1. Choose the required indexes, integers or sequence entries. Preserve decimal-string encodings where the field table specifies strings.
  2. Enter n, k, prime according to the field table, then run the tool.
  3. Read residue. Use the stated units, indexing and interpretation of the numerical result.
  4. Keep exact decimal strings for subsequent integer arithmetic; distinguish them from any explicitly approximate numeric result.
Input fieldMeaningValue type and boundsRequirement
nNonnegative upper binomial indexstring (integer/arbitrary); maximum text length 200; pattern ^(0|[1-9][0-9]*)$Required
kNonnegative lower binomial indexstring (integer/arbitrary); maximum text length 200; pattern ^(0|[1-9][0-9]*)$Required
primePrime modulus (resource limit 10000)integer; minimum 2; maximum 10000Required

Parse nonnegative n and k as BigInt strings and require a prime modulus at most 10000. Multiply digit-level numerator products and modular inverses; return zero when a lower digit exceeds its upper digit.

C(n,k) mod p = Π C(nᵢ,kᵢ) mod p, for base-p digits

The symbols and boundary conditions refer to the supplied fields and the implementation described above.

Output fieldMeaningValue type
residueBinomial coefficient modulo the primeinteger
json
{
  "input": {
    "n": "100",
    "k": "50",
    "prime": 7
  },
  "output": {
    "residue": 4
  }
}

Limitations and assumptions

The modulus must be prime. The output is a residue, not the full binomial coefficient, and both decimal indexes are limited to 200 characters.

Use the declared integer bounds and string formats. Large exact outputs remain decimal strings; numerical approximations use ordinary floating-point arithmetic. A rejected input is different from a valid zero count or false membership flag.

Alternative or Complementary methods

Choose q-Binomial Coefficient Polynomial when you need its operation: Return exact coefficients of the Gaussian binomial [n choose k]_q in ascending degree order, with zero for k>n and indices capped at 64. Choose Modular Inverse for the complementary operation: Find the least nonnegative inverse of a signed decimal integer modulo a decimal modulus of at least two, rejecting noncoprime pairs.

Background reference: Lucas’s Theorem.

References

  1. Lucas’s Theorem — Harvey Mudd College Math Fun Facts

Similar or alternative tools

  • q-Binomial Coefficient Polynomial

    Return exact coefficients of the Gaussian binomial [n choose k]_q in ascending degree order, with zero for k>n and indices capped at 64.

  • Modular Inverse

    Find the least nonnegative inverse of a signed decimal integer modulo a decimal modulus of at least two, rejecting noncoprime pairs.

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies