Tuesday, 13 September 2016

number theory - nchoosekbmodm using Chinese remainder theorem?



I don't really see too many sites explaining how this is done. Does anyone know how this works? I'm trying to find (nk)modm, where n and k are large and m is not prime. I think it can be done with the Chinese remainder theorem, but I don't understand how it is all put together.


Answer



Andrew Granville's paper Binomial coefficients modulo a prime power (you can find a copy here) has the following generalization of Lucas' Theorem:





Theorem. Let pq be a prime power, and let n=k+r be given. Write
k=k0+k1p++kdpd


in base p, and let Kj be the least positive positive residue of kpj(modpq) for each j0, so that
Kj=kj+kj+1p++kj+q1pq1;

make the same definitions for nj, Nj, rj, and Rj. Let ej be the number of indices ij for which niki (the number of "carries" when adding k and r in base p at or beyond the jth digit). Then
1pe0(nk)(±1)eq1((N0!)p(K0!)p(R0!)p)((N1!)p(K1!)p(R1!)p)((Nd!)p(Kd!)p(Rd!)p)(modpq),

where (±1) is 1 except when p=2 and q3, and (s!)p is the product of the positive integers less than or equal to s that are not divisible by p.





Granville then writes:




[This] Theorem[] provides a quick way to compute the value of the binomial coefficients modulo arbitrary prime powers, as it is straightforward to determine each of the nj, Nj, ej, etc. and then one need only determine the value of (s!)p(modpq) with k<pq[.]




Once you have the value modulo prime powers, the Chinese Remainder Theorem (whose proof is almost invariably given constructively in textbooks) tells you how to find the value modulo m.



In the special case where q=1, the Theorem yields Lucas' Theorem: if n0 and m0 are the least nonnegative remainders of n and m modulo p, then
(nm)(npmp)(n0m0)(modp),



if we interpret (rs)=0 when r<s.






How does the CRT put the information together? This is found in pretty much all textbooks of Elementary Number Theory that I am familiar with:



Suppose you know that x=(nk) satisfies congruences
xa1(modm1)xa2(modm2)xar(modmr)


where m1,,mr are pairwise coprime (e.g., pairwise distinct primes, or prime powers of pairwise distinct primes, or any other collection of integers that are pairwise coprime), and a1,,ar are arbitrary integers.



The Chinese Remainder Theorem says that there is a unique value of xmodm1××mr that satisfies all these congruences simultaneously.



The algorithmic method that appears in most textbooks is the following: for each i=1,,r, let
Mi=m1××mrmi.


That is, the product of all moduli except for the ith one. Then gcd(mi,Mi)=1, so we can find (e.g., by the Extended Euclidean Algorithm) integers si and ti such that

1=siMi+timi.

Do this for each i. Then let x be the remainder modulo m1××mr of
a1s1M1+a2s2M2++arsrMr.

Then x satisfies all the original congruences and is the unique integer modulo m1××mr that satisfies the original congruences: since Mi0(modmj) if ij and siMi1(modmi), we have that
a1s1M1++arsrMraisiMiai(modmi)for each i=1,2,,r.



For example: take B=(45651), m=30=2×3×5.



We find Bmod2, Bmod3, and Bmod5, e.g. using Lucas' Theorem.
456=0+0×21+0×22+1×23+0×24+0×25+1×26+1×27+1×28=0+2×31+2×32+1×33+2×34+1×35=1+1×5+3×52+3×5351=1+1×2+0×22+0×23+1×24+1×25=0+2×3+2×32+1×33=1+0×5+2×52


So
(45651)(01)(01)(00)(10)(01)(01)(10)(10)(10)(mod2)0(mod2)(45651)(00)(22)(22)(11)(20)(10)(mod3)=1(mod3)(45651)(11)(10)(32)(30)(mod5)=3(mod3).

So we are trying to find the value of x modulo 30 such that
x0(mod2)x1(mod3)x3(mod5).

We have M1=15, M2=10, M3=6. We can write
1=M17m1,1=M23m2,1=M3m3.

So the number we want is x=0M1+1M2+3M3=10+18=28mod30.



Hence (45631)28(mod30).



Note. There are nicer ways of solving the problem of combining the congruences into a single congruence modulo m1mr if you are working with pencil-and-paper; they can probably be programmed into a computer as well. Suppose we are trying to find the unique x modulo 30 such that x0(mod2), x1(mod3), and x3(mod5). From the first congruence, we know that x=2a for some a. Plugging into the second congruence, we have 2a1(mod3). Since 21(mod3), we have a1(mod3), or a2(mod3); hence, a=2+3b. Plugging into x=2a we have x=4+6b. Plugging this into the third congruence we have 4+6b3(mod5), or b14(mod5). So b=4+5c. Plugging into the formula for x we get
x=2a=2(2+3b)=4+6b=4+6(4+5c)=4+24+30c=28+30c,



that is, x28(mod30), same answer as before.



Note 2. In particular, Lucas' Theorem tells you how to compute (nk)modp for primes p. With Lucas' Theorem and the Chinese Remainder Theorem, you can compute (nk)modm for any squarefree integer m (exactly what Qiaochu said in his comment way back when). In order to compute (nk)modm for arbitrary integers m, first you need to factor m into prime powers,
m=pα11pαrr,


where p1,,pr are pairwise distinct primes and ai>0 for each i; then solve (nk)modpαii for each i (that is, compute the remainder modulo the prime powers; this can be done using Granville's generalization of Lucas' theorem given above); and then using the Chinese Remainder Theorem to combine all the congruences (nk)ai(modpαii) into a single congruence modulo pα11pαrr=m (exactly what André Nicolas said in his comment).


No comments:

Post a Comment

real analysis - How to find limhrightarrow0fracsin(ha)h

How to find limh0sin(ha)h without lhopital rule? I know when I use lhopital I easy get $$ \lim_{h\rightarrow 0}...