模除运算

C++ 中两数相除(假设被除数和除数都不是 0),同号则结果为正,异号则结果为负。模除运算则定义为:

If $a~/~b$ is representable in the result type, $(a~/~b)*b + a~\%~b == a$.(来自 https://en.cppreference.com/w/cpp/language/operator_arithmetic

实践起来则是:在被除数不是 0 的情况下,模除运算的结果总是和除数同正负。