Modulo n operation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.