An Introduction to Modular Math

두 정수를 나눌 때 다음과 같은 식을 사용할 것입니다:
start fraction, A, divided by, B, end fraction, equals, Q, space, r, e, m, a, i, n, d, e, r, space, R
A is the dividend
B is the divisor
Q is the quotient
R is the remainder
Sometimes, we are only interested in what the remainder is when we divide A by B.
For these cases there is an operator called the modulo operator (abbreviated as mod).
Using the same A, B, Q, and R as above, we would have: A, space, m, o, d, space, B, equals, R
We would say this as A modulo B is equal to R. Where B is referred to as the modulus.
예를 들어 봅시다:

Visualize modulus with clocks

숫자를 하나씩 증가시면서 3으로 나누면 어떻게 되는지 알아봅시다.
The remainders start at 0 and increases by 1 each time, until the number reaches one less than the number we are dividing by. After that, the sequence repeats.
이를 이해하면 모듈로 연산자를 원을 이용하여 나타낼 수 있습니다.
원의 제일 위에 0을 쓰고 오른쪽으로 정수 1 부터 모듈보다 하나 작은 수까지 시계방향으로 연속해서 씁니다.
For example, a clock with the 12 replaced by a 0 would be the circle for a modulus of 12.
To find the result of A, space, m, o, d, space, B we can follow these steps:
  1. Construct this clock for size B
  2. Start at 0 and move around the clock A steps
  3. Wherever we land is our solution.
(If the number is positive we step clockwise, if it's negative we step counter-clockwise.)

예시

8, space, m, o, d, space, 4, equals, question mark

With a modulus of 4 we make a clock with numbers 0, 1, 2, 3.
We start at 0 and go through 8 numbers in a clockwise sequence 1, 2, 3, 0, 1, 2, 3, 0.
We ended up at 0 so .

7, space, m, o, d, space, 2, equals, question mark

With a modulus of 2 we make a clock with numbers 0, 1.
We start at 0 and go through 7 numbers in a clockwise sequence 1, 0, 1, 0, 1, 0, 1.
We ended up at 1 so .

minus, 5, space, m, o, d, space, 3, equals, question mark

With a modulus of 3 we make a clock with numbers 0, 1, 2.
We start at 0 and go through 5 numbers in counter-clockwise sequence (5 is negative) 2, 1, 0, 2, 1.
We ended up at 1 so .

Conclusion

If we have A, space, m, o, d, space, B and we increase A by a multiple of , we will end up in the same spot, i.e.
A, space, m, o, d, space, B, equals, left parenthesis, A, plus, K, dot, B, right parenthesis, space, m, o, d, space, B for any integer .
예를 들어 봅시다:

Notes to the Reader

mod in programming languages and calculators

Many programming languages, and calculators, have a mod operator, typically represented with the % symbol. If you calculate the result of a negative number, some languages will give you a negative result.
e.g.
-5 % 3 = -2

Congruence Modulo

다음과 같은 식을 볼 수도 있을 겁니다:
AB (mod C) A \equiv B\ (\text{mod } C)
This says that A is congruent to B modulo C. It is similar to the expressions we used here, but not quite the same.
In the next article we will explain what it means and how it is related to the expressions above.