Work

Fast Start or Fast Repeat? Binomial Coefficients Modulo a Prime for N up to 10^18

Year: 2026
Type: preprint
Abstract: Evaluating binomial coefficients C(N, R) mod p when N reaches 10^18 and p < 2^31 is large enough to defeat linear O(p) precomputation forces an uncomfortable engineering choice between startup latency and query throughput. We investigate this tradeoff empirically by building and auditing two prime-modulus (k = 1) factorial backends inside a shared C++17 arithmetic pipeline. Compact, a square-root-block engine built for fast startup and tight RAM, uses a median peak working set of 5.9 MB and a 6.2 ms first-query latency across all 48 expensive benchmark cases. Warm—a dense-block engine tuned for heavy reuse—uses 7.0 MB and 22.6 ms, whereas Stock Suisen requires 18.0 MB and 56.4 ms. Against Stock Suisen, Warm achieves equal-case geometric-mean speedups of 2.141x on cold batches (48/48 wins) and 2.262x on warm batches (47/48 wins), while beating Compact on warm batches by 12.137x. On cold batches where construction cost cannot be amortized, Compact beats Warm in 44 of 48 expensive cases; Frozen Nyaan wins 26/48, and Balanced Suisen wins 31/48. Control-case regressions are reported alongside these wins without omission. Companion C++17 library (MIT License), exact-reference tests (319,910 checks per compiler on GCC and Clang), and supplementary audit tables: https://github.com/Vadik-x/prime-modulus-binomial-tradeoff
Author: Malik, Vadik
Language: English
Open Access status: green
OpenAlex ID: W7237665147
Cites:
Cited by:
Related to: