-1

I was checking some websites about modular arithmetic, and i read this :

(x + y) % n = (x % n) + (y % n)

Is this correct ?

What if we take : x = 4, y = 2, n = 5 ? We will have 1 = 6 !?

  • 1
    $1\equiv 6 \mod 5$ – A. Goodier Aug 26 '20 at 11:52
  • When working in modulo 5, $1\equiv 6$. So you have to see this through the "modular" lenses ... – Matti P. Aug 26 '20 at 11:52
  • 2
    The confusion stems from the fact that the operator $%$ is not used consistently. Some people use $a%n$ to refer to the residue class $a\pmod n$ Others use it to refer to the remainder you get on dividing $a$ by $n$. These are closely related notions, clearly, but they are not the same. – lulu Aug 26 '20 at 11:57
  • @WassimJaoui That's precisely what Wuestenfux said. – Matti P. Aug 26 '20 at 12:11
  • @MattiP. this means there's no difference between (x % n) + (y % n) and ((x % n) + (y % n)) %n ? When we are talking about residue class ( modified comment ) – Wassim Jaoui Aug 26 '20 at 12:26

1 Answers1

1

Correct is

$(x + y) \div n = [(x \div n) + (y \div n)] \div n$.

Wuestenfux
  • 20,964