The q-ary residue and necklace equality: prime classification and finite exceptional lengths

When do a residue count and a necklace count agree exactly? For integers \(n\ge1\), \(0\le k\le n\), \(0\le r<n\) and \(q\ge2\), let \(S\) count size-\(k\) multisets of \(\{1,\ldots,n\}\) whose entries sum to \(r\) modulo \(n\) and whose multiplicities are at most \(q-1\). Let \(N\) count length-\(n\) words over \(\{0,\ldots,q-1\}\), up to cyclic rotation, whose entries sum to \(k\) and whose co-period divides \(r\). The co-period is \(n\) divided by the least positive rotation that fixes the word, so it counts the repetitions of its shortest block. The classification gives a closed arithmetic test for prime \(q\) and an exact finite test for composite \(q\), answering the question in its full stated domain. Dougherty-Bliss and Elizalde, §6, Problem 6.6 Put \(h=\gcd(n,k)\) and \(G=\gcd(h,q)\). The equality conditions are as follows. If \(k=0\), both counts are \(1\) at \(r=0\) and \(0\) otherwise. For \(q=2\) and \(k>0\), equality holds exactly when at least one of these conditions holds: \(n\) is odd, \(k\) is odd, \(\nu_2(n)<\nu_2(k)\), \(r>0\) and \(\nu_2(k)-\nu_2(r)\ge2\), or \(n=k\) is even and \(r\notin\{0,n/2\}\). Here \(\nu_2(b)\) is the exponent of \(2\) in the positive integer \(b\); the fourth condition is stated with positive \(r\) so that no valuation of zero is needed. Original binary classification, Theorem 4.7 For \(q\ge3\), equality always holds if \(k<q\) or \(G=1\). For odd prime \(q\), the only additional equality is at \(q=3\), \(n=k=6\), with \(r\) even. For composite \(q\) with \(G>1\) and \(k=q\), the counts differ. The exact difference at \(k=q\) is \(N-S=G\mathbf 1_{G\mid r}-1\), where an indicator \(\mathbf 1_A\) equals \(1\) when \(A\) holds and \(0\) otherwise. For composite \(q\) with \(G>1\) and \(k>q\), let \(p\) be the smallest prime dividing \(G\), \(\rho=\gcd(r,h)\) and \(u=(k-q)/p\). Equality holds exactly when \(n\) belongs to the set constructed below. For each fixed \((q,k,h,\rho)\), this set has at most \(u\) members, all in \(k\le n<16k^4\). At every \(n\ge16k^4\) in this case, \(N>S\) if \(p\mid r\), and \(N<S\) otherwise. The original counting formulae in Theorems 5.1 and 5.2 give an exact expression for the difference. For each divisor \(d\mid h\), write \(g=\gcd(d,q)\), \(a=q/g\), \(m=n/d\) and \(t=k/d\). With \([y^t]\) denoting coefficient extraction at degree \(t\), the expression is \[n(N-S)=\sum_{d\mid h}c_d(r)[y^t](1-y)^{-m}\big((1-y^q)^m-(1-y^a)^{gm}\big). \] Here \(c_d(s)=\sum_{e\mid\gcd(d,s)}e\mu(d/e)\) is the Ramanujan sum. The Möbius function \(\mu(b)\) is zero if \(b\) has a squared prime factor and is \((-1)^j\) if \(b\) is a product of \(j\) distinct primes, with \(\mu(1)=1\). The terms with \(g=1\) or \(t<a\) vanish. In the remaining composite case, the term for \(d=p\) has strictly highest degree as a polynomial in the length. Beyond the cutoff it controls the sign because its coefficient polynomial is positive and its weight \(c_p(r)\) is \(p-1\) for \(p\mid r\) and \(-1\) otherwise. To construct the exceptional set, use only divisors \(d\mid h\) with \(g>1\) and \(dq/g\le k\). For each such \(d\), keep \(t=k/d\) and compute two polynomial sequences in the indeterminate \(X\), one for \(b=q\) and one for \(b=q/g\). Start with \(V_0^{(b)}(X)=1\), and for \(1\le j\le t\) set \[V_j^{(b)}(X)=X\sum_{i=1}^{j}(j-1)_{i-1}d^{i-1}\big(1-q\mathbf 1_{b\mid i}\big)V_{j-i}^{(b)}(X), \] where \((s)_\ell=s(s-1)\cdots(s-\ell+1)\) and \((s)_0=1\). Form the integer polynomial \[P(X)=\sum_d c_d(\rho)\frac{k!}{t!d^t}\big(V_t^{(q)}(X)-V_t^{(q/g)}(X)\big), \] using the same divisors. The factorial ratio is integral because \(t!d^t\) is the product of the positive multiples of \(d\) up to \(k\). At an input length in the specified gcd class, \(P(n)=k!n(N-S)\). The polynomial \(P(X)/X\) has degree exactly \(u\). Set \(J=\{j\in\mathbb Z:k\le j<16k^4,\ \gcd(j,k)=h\}\). The exceptional lengths are the roots of the monic polynomial \[\gcd_{\mathbb Q[X]}\!\left(P(X)/X,\ \prod_{j\in J}(X-j)\right). \] Equivalently, find the integer roots of \(P(X)/X\) and retain those in \(J\). The construction has polynomial bit cost in \(k\) in this range, and the resulting set can be reused for every \(n,r\) with the same \(h,\rho\). For example, at \(q=6\), \(k=h=15\) and \(\rho=1\), the polynomial is \(-8072064000X^2(X-3)(X-15)\). Each other possible \(\rho\) changes it only by a nonzero scalar. The only admissible root is \(n=15\), so at this length the counts agree for every residue.

Authors

Institutions

Publication Details

Journal
Zenodo (CERN European Organization for Nuclear Research)
Published
2026-12-03
DOI
https://doi.org/10.5281/zenodo.24794444
Primary Topic
Advanced Combinatorial Mathematics
Type
preprint
Controls
|||
ALL TIME
JAN
FEB
MAR
APR
MAY
JUN
JUL
AUG
SEP
OCT
NOV
preprint

The q-ary residue and necklace equality: prime classification and finite exceptional lengths

Zixuan He
Zenodo (CERN European Organization for Nuclear Research)
Advanced Combinatorial Mathematics
preprint

The q-ary residue and necklace equality: prime classification and finite exceptional lengths

Zixuan He
preprint en

Abstract

When do a residue count and a necklace count agree exactly? For integers \(n\ge1\), \(0\le k\le n\), \(0\le r<n\) and \(q\ge2\), let \(S\) count size-\(k\) multisets of \(\{1,\ldots,n\}\) whose entries sum to \(r\) modulo \(n\) and whose multiplicities are at most \(q-1\). Let \(N\) count length-\(n\) words over \(\{0,\ldots,q-1\}\), up to cyclic rotation, whose entries sum to \(k\) and whose co-period divides \(r\). The co-period is \(n\) divided by the least positive rotation that fixes the word, so it counts the repetitions of its shortest block. The classification gives a closed arithmetic test for prime \(q\) and an exact finite test for composite \(q\), answering the question in its full stated domain. Dougherty-Bliss and Elizalde, §6, Problem 6.6 Put \(h=\gcd(n,k)\) and \(G=\gcd(h,q)\). The equality conditions are as follows. If \(k=0\), both counts are \(1\) at \(r=0\) and \(0\) otherwise. For \(q=2\) and \(k>0\), equality holds exactly when at least one of these conditions holds: \(n\) is odd, \(k\) is odd, \(\nu_2(n)<\nu_2(k)\), \(r>0\) and \(\nu_2(k)-\nu_2(r)\ge2\), or \(n=k\) is even and \(r\notin\{0,n/2\}\). Here \(\nu_2(b)\) is the exponent of \(2\) in the positive integer \(b\); the fourth condition is stated with positive \(r\) so that no valuation of zero is needed. Original binary classification, Theorem 4.7 For \(q\ge3\), equality always holds if \(k<q\) or \(G=1\). For odd prime \(q\), the only additional equality is at \(q=3\), \(n=k=6\), with \(r\) even. For composite \(q\) with \(G>1\) and \(k=q\), the counts differ. The exact difference at \(k=q\) is \(N-S=G\mathbf 1_{G\mid r}-1\), where an indicator \(\mathbf 1_A\) equals \(1\) when \(A\) holds and \(0\) otherwise. For composite \(q\) with \(G>1\) and \(k>q\), let \(p\) be the smallest prime dividing \(G\), \(\rho=\gcd(r,h)\) and \(u=(k-q)/p\). Equality holds exactly when \(n\) belongs to the set constructed below. For each fixed \((q,k,h,\rho)\), this set has at most \(u\) members, all in \(k\le n<16k^4\). At every \(n\ge16k^4\) in this case, \(N>S\) if \(p\mid r\), and \(N<S\) otherwise. The original counting formulae in Theorems 5.1 and 5.2 give an exact expression for the difference. For each divisor \(d\mid h\), write \(g=\gcd(d,q)\), \(a=q/g\), \(m=n/d\) and \(t=k/d\). With \([y^t]\) denoting coefficient extraction at degree \(t\), the expression is \[n(N-S)=\sum_{d\mid h}c_d(r)[y^t](1-y)^{-m}\big((1-y^q)^m-(1-y^a)^{gm}\big). \] Here \(c_d(s)=\sum_{e\mid\gcd(d,s)}e\mu(d/e)\) is the Ramanujan sum. The Möbius function \(\mu(b)\) is zero if \(b\) has a squared prime factor and is \((-1)^j\) if \(b\) is a product of \(j\) distinct primes, with \(\mu(1)=1\). The terms with \(g=1\) or \(t<a\) vanish. In the remaining composite case, the term for \(d=p\) has strictly highest degree as a polynomial in the length. Beyond the cutoff it controls the sign because its coefficient polynomial is positive and its weight \(c_p(r)\) is \(p-1\) for \(p\mid r\) and \(-1\) otherwise. To construct the exceptional set, use only divisors \(d\mid h\) with \(g>1\) and \(dq/g\le k\). For each such \(d\), keep \(t=k/d\) and compute two polynomial sequences in the indeterminate \(X\), one for \(b=q\) and one for \(b=q/g\). Start with \(V_0^{(b)}(X)=1\), and for \(1\le j\le t\) set \[V_j^{(b)}(X)=X\sum_{i=1}^{j}(j-1)_{i-1}d^{i-1}\big(1-q\mathbf 1_{b\mid i}\big)V_{j-i}^{(b)}(X), \] where \((s)_\ell=s(s-1)\cdots(s-\ell+1)\) and \((s)_0=1\). Form the integer polynomial \[P(X)=\sum_d c_d(\rho)\frac{k!}{t!d^t}\big(V_t^{(q)}(X)-V_t^{(q/g)}(X)\big), \] using the same divisors. The factorial ratio is integral because \(t!d^t\) is the product of the positive multiples of \(d\) up to \(k\). At an input length in the specified gcd class, \(P(n)=k!n(N-S)\). The polynomial \(P(X)/X\) has degree exactly \(u\). Set \(J=\{j\in\mathbb Z:k\le j<16k^4,\ \gcd(j,k)=h\}\). The exceptional lengths are the roots of the monic polynomial \[\gcd_{\mathbb Q[X]}\!\left(P(X)/X,\ \prod_{j\in J}(X-j)\right). \] Equivalently, find the integer roots of \(P(X)/X\) and retain those in \(J\). The construction has polynomial bit cost in \(k\) in this range, and the resulting set can be reused for every \(n,r\) with the same \(h,\rho\). For example, at \(q=6\), \(k=h=15\) and \(\rho=1\), the polynomial is \(-8072064000X^2(X-3)(X-15)\). Each other possible \(\rho\) changes it only by a nonzero scalar. The only admissible root is \(n=15\), so at this length the counts agree for every residue.

Zenodo (CERN European Organization for Nuclear Research)
University of Glasgow (GB)
Advanced Combinatorial Mathematics
AI Navigator

Ask Laika to Summarize, Analyze, and Connect papers live on the map.

Summarize Papers & Methodologies

Extract key findings, datasets, and comparative methods across publications.

Benchmark Rankings & Visual Analytics

Rank top research institutions, authors, funders, topics, and journals by Field-Weighted Citation Impact (FWCI) and paper volume with instant charts.

Connect Distant Disciplines

Bridge topological clusters on the map to find hidden collaborative intersections.

Laika access coming soon