In mathematics, integer division is usually rounded down to negative infinity, and the modulo sign is the same as the βdividerβ, or it is equal to zero: -10 mod 3 = 2 and 10 mod -3 = -2 (the coefficient is rounded to - 4). In C / C ++, integer division is rounded to zero, and the% sign coincides with the sign "dividend" or "numerator" or equal to zero, -10 mod 3 = -1 and 10 mod -3 = 1 (the factor is rounded to zero to - 3). When performing a mathematical model of the final field with C / C ++, you need to perform corrections for corrections so that the results meet the mathematical definition of modulo. For example, if X% 3 = -1, add 3 so that X mod 3 = +2.
Assuming C is positive, a mathematical field modulo C consists of the numbers {0, 1, ... C-1} without any negative numbers. If C is negative (this is unusual for modulo), then the field is {0, -1, -2, ... C + 1}. Assuming C is positive, then if A or B is negative, then you can still use ((A% C) + (B% C))% C and then send the correct answers if the result is negative by adding C to the result .
source share