3

In my number theory textbook I am tasked with finding the value of $5^{30}\mod 62$. As the last section had been about Eulers Theorem which states that for any $a,n\in\mathbb{Z}$ where the $\gcd(a,n)=1$ $$a^{\phi(n)}\equiv1\mod n$$ The first thing I check was therefore what $\phi(62)$ is, and as $\phi(62)=30$ and $\gcd(5,62)=1$, I got the result $$5^{30}\equiv1\mod 62$$ However when I double checked my anwser with MatLab I recived the anwser

>>mod(5^(30),62) = 44

And now I don't whats wrong, is this an error with my MatLab code or an error with my Number Theory?

Bill Dubuque
  • 282,220
Ilikemath
  • 358
  • 2
    I'm not familiar enough with MatLab, but it probably can't handle large integers. – jjagmath Nov 06 '24 at 19:16
  • 2
    It's likely a numerical issue with Matlab. You can check easily that $5^{10}\equiv 5 \mod 62$ and hence $5^{30}\equiv 5^{3}\equiv 1 \mod 62$. Perhaps Matlab can check those middle steps for you. – Jorge I. González C. Nov 06 '24 at 19:18
  • 1
    use powermod(a,b,m) for $a^b \mod m$ https://uk.mathworks.com/help/symbolic/sym.powermod.html – Matthew Towers Nov 06 '24 at 19:21
  • 3
    I assumed that if the numbers were too big MatLab would have returned NaN and by using powermod(5,30,62) I get the correct anwser of 1. – Ilikemath Nov 06 '24 at 19:21
  • $5^{30} \equiv 1 \pmod{62}$ is correct. R = IntegerModRing(62); R(5^30) on Sage indeed returns 1. – SchellerSchatten Nov 06 '24 at 19:24
  • 1
    If you don't want to deal with symbolic numbers, a quick way around is to compute mod(5^15,62) and check the result squared mod 62 etc. – RobinSparrow Nov 06 '24 at 20:23

2 Answers2

5

You are correct in your theoretical reasoning. Note that $$\log_2(5^{30}) = 30 \times\log_25 \approx 69.7.$$ You need at least 70 bits to represent this number; typical Matlab integer types are 8, 16, 32, and 64 bits long. Instead you should use symbolic numbers to get

x = sym(5)^30;
y = mod(x, 62)
  • Thank you for the explanation, I was unaware of the typical integer types and I though MatLab would inform me if it were too big, I see I was wrong to think so. I will do further research into big numbers and MatLab. – Ilikemath Nov 08 '24 at 18:29
5

Definitely some sort of issue with your computer (or your input): $$5^{30}\equiv 1\pmod {62},$$ because, for instance, $$5^3\equiv 125\equiv 1\pmod {62}.$$

Then $$5^{30}\equiv (5^3)^{10}\equiv 1^{10}\equiv 1\pmod {62}.$$

  • 1
    Nice, that's a very fool-proof way to see it. – Adayah Nov 07 '24 at 07:18
  • In this case, $3$ is the order of $5\pmod {62}.$ Whenever you raise a group element to a power a multiple of its order, you get $1.$ This is a little group/number theory lingo. @Adayah – suckling pig Nov 10 '24 at 05:13