I try to use $$122^{122} = 2^{122} (\mod 10)$$
But I use MATLAB that $122^{122}=2 (\mod 10)$ and $2^{122}=4 (\mod 10)$. Why they are not the same? The screenshot is as follows:
I try to use $$122^{122} = 2^{122} (\mod 10)$$
But I use MATLAB that $122^{122}=2 (\mod 10)$ and $2^{122}=4 (\mod 10)$. Why they are not the same? The screenshot is as follows:
You can use the Chinese remainder theorem. Since $2$ and $10$ aren't relatively prime, Euler isn't directly applicable.
$10=2\cdot5$, and $2^{122}\equiv0\bmod2$. We get $\varphi (5)=4\implies2^{122}\equiv2^2\equiv4\bmod5$, and the answer is $4$.
$122^{122} \equiv 2^{122} (\text{mod $10$})$
As, $2^5\equiv 2 (\text{mod $10$})$ $\implies 2^{120}\equiv 2^{24} \equiv 2^{4} (\text{mod $10$})$ $\implies 2^{122} \equiv 2^{6} \equiv 4 (\text{mod $10$})$
Look at the general problem of find the last digit of $n^m$.
Take $n=10N+h$ where $0\le h\le9$ and $m=4M+k$ where $0\le k\le3$.
Power of digits have a period of $4$ modulo $10$ the following way: $$1\to1\to1\to1\\2\to4\to8\to6\\3\to9\to7\to1\\4\to6\to4\to6\\5\to5\to5\to5\\6\to6\to6\to6\\7\to9\to3\to1\\8\to4\to2\to6\\9\to1\to9\to1$$
Example: $797^{723}=(10N+7)^{4\cdot180+3}\equiv7^3\pmod{10}=3\pmod{10}$.
Apply this to find the answer to your problem.
I no longer have access to Matlab so I can't reproduce this error exactly on my end. A similar mistake is observed when I use Octave online:
octave:2> mod(122^122, 10)
ans = 0
You should use a function such as powermod. The trick is we do not want to compute $122^{122}$ explicitly.
Notice that $122^{122}$ is a very large number and it is working in double precision float point that exceeds flintmax. Above this value, double-precision format does not have integer precision, and not all integers can be represented exactly.
The answer is indeed $4$.
Here are the Python outcome:
>>> 122**122 % 10 # cool, it can be computed
4
>>> pow(122, 122, 10) # preferred.
4
mod(122^122,10)=2
? – Hermi Dec 21 '20 at 01:59