What is modular arithmetic?
Modular arithmetic is a generalization of parity. We say a b (mod n) if n divides a b. There are n residue classes modulo n. That is every integer is congruent to one of 0;1;2;3;:::;n 1 modulo n. Rather than giving an account of properties of modular arithmetic, we give examples of its applications to contests.
How is modulo n used in arithmetic?
Modular arithmetic can be handled mathematically by introducing a congruence relation on the integers that is compatible with the operations of the ring of integers: addition, subtraction, and multiplication. For a positive integer n, two integers a and b are said to be congruent modulo n, written:
How do you divide n 3 in modular arithmetic?
n 3 ? n = n ( n + 1) ( n ? 1) is always divisible by 2 and 3, so it is 0 mod 6. Note: I marked this answer community wiki because I got the answer form the comment. by exhaustive checking. If you want to use purely modular arithmetic, then you must prove that both 3 and 2 divide your function. So, we use Fermat's little theorem. So, 3 divides this.
How to do modular addition?
That's the basic of modular artihmetic. Here r is the mod. We can perform addition of mods. We'll have to calculate mods of numbers seperately and then add them together and perform mod again of the sum. Let's take a = 40, b = 3 and m = 5. So, we want to calculae, (40 + 3) mod 5. That's modular addition.