# Grox's Sequence I: A Polynomial Coefficient Recurrence ## Counting Identity First work over the rationals with exponential generating functions. Arbitrary counts, even counts, and zero or positive odd counts correspond to $e^x$ , $\cosh x$ , and $1+\sinh x$ . Multiplication accounts for the binomial choices of labelled positions for different symbols. The answer is therefore $$N![x^N]\ e^{ax}(\cosh x)^b(1+\sinh x)^c.$$ Let $d=2(b+c)$ and define $$F(z)=(1+z^2)^b(z^2+2z-1)^c=\sum_{i=0}^{d}f_i z^i.$$ Writing the hyperbolic functions as exponentials gives the answer identity $$2^{-(b+c)}\sum_{i=0}^{d}f_i(a-b-c+i)^N.$$ This is first an identity over the rationals. Clearing the power-of-two denominator gives an integer identity, so it can be reduced modulo $p$ for arbitrarily large $N$ . We never divide by $N!$ in the modular field; only the inverse of two is needed. The zero-occurrence option of the third group creates the coefficient $2z$ , which must be included. ## Large Exponents and Implementation Boundaries Read $a\bmod p$ and $N\bmod(p-1)$ digit by digit, while separately tracking whether $N$ is actually zero. Fermat's theorem reduces exponents only for nonzero bases. A zero base raised to a positive exponent gives zero; an actual zero exponent gives one. In particular, a positive multiple of $p-1$ is not an empty sequence length. Normalize residues into $[0,p-1]$ . Use 64-bit products and reduce immediately; $p^2<2^{63}$ ensures safety. Every small integer inverted below is at most $d