Note: This is just my personal understanding. It may be incorrect.
For integers A and N, the modulo n operation is to calculate the remainder of a divided by N.
If a = 10, n = 3, the quotient of a divided by N is 3, and the remainder is 1.
C language and other programming languages often use % representing the modulo operation: A % N
10% 3 = 1
MoD is also used in English to represent the modulo operation: A mod n
10 mod 3 = 1
Addition of the modulo n operation:
(A + B) % N = (a % N + B % N) % N
Subtraction of the modulo n operation:
(A-B) % N = (a % N-B % N) % N
Multiplication of the modulo n operation:
(A * B) % N = (A * (B % N) % N = (a % N) * B) % N = (a % N) * (B % N) % N
Multiplication of the modulo n operation:
(A ^ B) % N = (a % N) ^ B) % N
(A ^ B) % N) * (a ^ c) % N = (a % N) ^ B) % N) * (a % N) ^ c) % N = (a % N) ^ B) * (a % N) ^ C )) % N = (a % N) ^ (B + C) % N = (a ^ (B + C) % N
Abstract The addition, subtraction, and multiplication operations in the N operation:
If % N in the preceding equation is omitted from the equation, and then the formula (mod N) is used to mark the equation, it indicates that the calculation is not a common addition, subtraction, multiplication, and other operation, is based on the modulo n operation, then each operation can write:
A + B = a + B (mod N)
A-B = A-B (mod N)
A * B = a * B (mod N)
A ^ B = a ^ B (mod N)
(A ^ B) * (a ^ c) = a ^ (B + C) (mod N)
In this way, the addition and subtraction multiplication operation based on mod n is obtained.
B ^ (-1) Definition
For normal multiplication, B * B ^ (-1) = 1, then B ^ (-1) based on modulo n should meet the following requirements:
B * B ^ (-1) = 1 (mod N)
As can be seen from (2*5) % 3 = 1
2 ^ (-1) = 5 (mod 3)
5 ^ (-1) = 2 (mod 3)
As can be seen from (2*2) % 3 = 1
2 ^ (-1) = 2 (mod 3)
We can see that B ^ (-1) is a series of numbers, but usually only the value of <n
B ^ (-1) is also called the modulo antielement of B about N.
Defined by B ^ (-1), we can obtain an abstract division based on modulo n.
A/B = A * (B ^ (-1) (mod N)
Modulo n operation