How do I efficiently compute abmodc:
- When b is huge, for instance 5844325mod21?
- When b is less than c but it would still be a lot of work to multiply a by itself b times, for instance 569mod101?
- When (a,c)≠1, for instance 6103mod14?
Are there any other tricks for evaluating exponents in modular arithmetic?
This is being asked in an effort to cut down on duplicates, see here: Coping with *abstract* duplicate questions.
and here: List of Generalizations of Common Questions
Answer
Wikipage on modular arithmetic is not bad.
When b is huge, and a and c are coprime, Euler's theorem applies:
ab≡abmodϕ(c)modc
For the example at hand, ϕ(21)=ϕ(3)×ϕ(7)=2×6=12. 844325mod12=5, so 55=5×252≡5×42=80≡17mod21.When a and c are coprime, but $054≡5×53≡5×24≡19(mod101)194≡(192)2≡582≡(−43)2≡1849≡31(mod101)314≡(312)2≡(961)2≡522≡2704≡78(mod101)569≡5×54×((54)4)4≡5×19×78≡5×19×(−23)≡19×(−14)≡−266≡37(mod101)
When a and c are not coprime, let g=gcd(a,c). Let a=g×d and c=g×f, then, assuming b>1:
abmodc=gb×dbmod(g×f)=(g×(gb−1dbmodf))modc
In the example given, gcd(6,14)=2. So 2102×3103mod7, using Euler'r theorem, with ϕ(7)=6, and 102≡0mod6, 2102×3103≡3mod7, so 6103≡(2×3)≡6mod14.
No comments:
Post a Comment