1

I'm doing a programming challenge and I can't wrap my head around of finding an Euler totient when the modulus and the base aren't co-primes.
So I have:
$$4 ^ {4 ^ 4}(mod\;10)$$ I understand that 4 and 10 aren't co-primes. So I've tried to use mod distributive law and then find a totient, but it doesn't work. In a task it is said that it's possible somehow to modify the totient function that it will work with non-coprimes. I know how totient function works, I know properties of it and how to find a totient, but only with co-primes.
P.S. I'm making an algorithm so shortcuts like $(-1)^n$ etc won't work.

CaseMon
  • 31
  • 1
    Do you mean $4^{4^4}$ or $(4^4)^4$? Also, could you clarify what you mean by "shortcuts like $(-1)^n$ won't work"? – Damian Pavlyshyn Nov 10 '22 at 22:20
  • the first version in your comment. I mean I've seen so many shortcuts for example 2 = -1 mod 3 and then (-1) ^ n. When doing a programming challenge it won't work. I put this example just in case someone says do it very easy, while I'm looking for a general approach to the problem. – CaseMon Nov 10 '22 at 22:22
  • So, you want $4^{256}\pmod {10}$, yes? Can you see that it suffices to compute it $\pmod 2$ and $\pmod 5$ separately? – lulu Nov 10 '22 at 22:25
  • @lulu yes. I've tried this way but stack here too. Because 4 ^ 256 ( mod 2), so 4(mod 2) = 0 or I'm missing something here. – CaseMon Nov 10 '22 at 22:29
  • I don't know what you mean by "finding an Euler totient". Why not just say, you are trying to evaluate $4^{4^4}\bmod{10}$? Anyway, yes $4\bmod2=0$, so all you have to do is work out $4^{256}\bmod5$, and since $4^2=1\bmod5$, you'll get $4^{256}=1\bmod5$. Putting it together, $4^{256}=6\bmod{10}$. – Gerry Myerson Nov 10 '22 at 22:37
  • @GerryMyerson that's a nice solution. But I'm looking for a little bit more general solution. Because 4^2 = 1(mod 5) is easy to do while doing by hand, but not so while programming. – CaseMon Nov 10 '22 at 22:44
  • Well, since five's a prime, we know by Fermat that $4^4\equiv1\bmod5$, so you can take it from there. – Gerry Myerson Nov 10 '22 at 22:55
  • @GerryMyerson thanks, it works now. – CaseMon Nov 10 '22 at 23:59
  • Good. Let me encourage you to write something up, and to post it as an answer. – Gerry Myerson Nov 11 '22 at 05:47
  • @GerryMyerson, sure, a little bit later though. I need to work out some calculations and dig a bit deeper in modular arithmetic to give a coherent answer. Actually I'm not really sure whether I need to give a complete answer or just somehow mark the best answer and that's it. First time posting here. – CaseMon Nov 11 '22 at 08:58
  • You can't mark the best answer until someone posts an answer – comments don't count. But if you can post an answer you're happy with (and "later" is fine), then you can accept it, too. – Gerry Myerson Nov 11 '22 at 10:20

1 Answers1

2

I solved the problem by using Chinese reminder theorem for prime values of $(mod\;10)$, i.e. $(mod\;(2*5))$ \begin{cases} x = 4^{4^4}(mod\;2)\\ x = 4^{4^4}(mod\;5)\\ \end{cases} \begin{cases} x = 4^{4^4}(mod\;2)=0\\ x= 4^{4^4}(mod\;5) = 4^{4(mod\;\phi(5))}(mod\;5) = 4^0(mod\;5) = 1(mod\;5)\\ \end{cases} where $\phi(n)$ is Euler's totient function. Although I could use the simplification $4^2 = 1(mod\;5)$as mentioned in the comments, but for an algorithm it's easier to find a totient. Next step is to put the values into the Chinese reminder formula $$x = 0* \frac{10}{2}*(\frac{10}{2})^{-1}(mod\;2) + 1* \frac{10}{5}*(\frac{10}{5})^{-1}(mod\;5) $$ which equals to $$x = 0 + 1 * 2*2^{-1}(mod\;5) $$ $$2^{-1}(mod\;5) = 2^{\phi(5) - 1}(mod\;5) = 2^3(mod\;5) = 3(mod\;5)$$ So the result is $$x = 0 + 2 * 3 = 6(mod\;10)$$ Thanks everyone.
More resources for future reference:
Specific steps in applying the Chinese Remainder Theorem to solve modular problem splitting modulus https://en.wikipedia.org/wiki/Modular_arithmetic

CaseMon
  • 31