MoD () is the remainder function
MoD (15, 7) = 1
MoD (15,-7) =-6
MoD (-15, 7) = 6
MoD (-15,-7) =-1
15 = 7 * 2 + 1
15 = (-7) * (-3) + (-6)
-15 = 7 * (-3) + 6
-15 = (-7) *2 + (-1)
The divisor, divisor, quotient, and remainder are respectively recorded as M, N, p, q (M, n, p, n >= 0)
Then there are:
m = n * p1 + q1
m = (-N) * (-P2) + (-Q2)
-M = n * (-P3) + Q3
-M = (-N) * P4 + (-Q4)
The positive and negative signs of divisor, divisor, quotient and remainder are as follows:
Dividend
Divisor
Business
Remainder
+
+
+
+
+
-
-
-
-
+
-
+
-
-
+
-
Rule 1: The symbol of the divisor = remainder.
Rule 2: The relationship between the two symbols of divisor and divisor:
Case 1: The same number, the symbol of the business is positive (symbol or);
Case 2: The sign of the quotient is negative (the symbol is the same or) when the number is different.
Rule 3: Business to be as small as possible (positive numbers closer to 0 smaller, negative numbers farther away from 0 smaller). The remainder is used to fill the absolute value of the remainder < divisor.
Rule 4: Quotient p1 = P4;-p2 =-p3;
Rule 5: Remainder Q1 + (-q4) = 0; (-q2) + q3 = 0;
Q1 + q3 = N; (-q2) + (-q4) =-n;q1 + | (-Q2) | = N;q3 + | (-Q4) | = N
(where | | is the absolute value symbol)