$$2012^{2011} \equiv x \pmod {14}$$
I need to calculate that, all the examples I've found on the net are a bit different. Thanks in advance!
$$2012^{2011} \equiv x \pmod {14}$$
I need to calculate that, all the examples I've found on the net are a bit different. Thanks in advance!
By the Chinese remainder theorem, knowing what something is modulo $2$ and what it is modulo $7$ is equivalent to knowing what it is modulo $14$.
Clearly, $2012^{2011}\equiv 0\bmod 2$.
Next, note that because$$2012\equiv 3\bmod 7$$ we have $$2012^{2011}\equiv 3^{2011}\bmod 7.$$ By Fermat's little theorem, we know that $$3^6\equiv 1\bmod 7$$ so that $$2012^{2011}\equiv 3^{2011}\equiv 3^{(6\cdot 335)+1}\equiv (3^6)^{335}\cdot 3\equiv 3\bmod 7.$$ Putting this back together with the help of the Chinese remainder theorem (or just direct observation if you prefer) we see that $$2012^{2011}\equiv 10\bmod 14.$$
Observe that $2012$ is $10$ mod $14$.
The powers of $10$ mod $14$ are: $10, 2, 6, 4, 12, 8$, after which they cycle.
Given the six remainders above, we now consider $10^{2011}$ mod $14$.
Since $2011 = 6 \cdot 335 + 1$, the expression cycles through the six remainders $335$ times, before finally stopping back on the first remainder: $10$.
Therefore, $2012^{2011}$ mod $14 = 10^{2011}$ mod $14 = 10$ mod $14$.
As $(2012,7)=1$ using Fermat's Little Theorem $2012^6\equiv1\pmod 7$
$$\text{As } 2010\equiv0\pmod 6, 2012^{2010}\equiv1 \pmod 7=1+7a\text{ for some integer }a$$
$$\implies 2012^{2011}=2012\cdot 2012^{2010}=2012(1+7a)\equiv2012\pmod{14}$$
$$\text{Now,} 2012=2100-88\equiv-88\equiv10\pmod{14}$$
Using my own programming language from the shell command line:
$ txr -c "@(bind a @(exptmod 2012 2011 14))"
a="10"
How that works internally is in binary. The exponent 2011 is considered to be a sum of powers of two. It's better to use a simpler example, like $13^{11} \mod 5$, which is $13^{8 + 2 + 1} \mod 5$ which is $13^813^213 \mod 5$. The factors are evaluated by repeated squaring, and reducing modulo 5, so the intermediate product is always in the range 0 to 4. If we square $13$ we get $13^2$. If we square that again we get $13^4$. If we square that, we get $13^8$. Repeated squaring gets us the power of two exponents, and we multiply together those ones which correspond to the powers of two present in the exponent, all modulo our modulus.
Although this is part of the bignum support, calculating $2012^{2011}\mod 14$ does not invoke any bignums. Repeatedly squaring $2012$ and reducing modulo $14$ can be done with 32 bit integer arithmetic.