商余数定理指出,对于任何一对整数 a 和 b(b 为正),存在两个唯一整数 q 和 r,使得:
a = b x q + r
where 0 <= r < b
示例 1:
如果 a = 22, b = 4
那么 q = 5, r = 2
22 = 4 x 5 + 2
示例 2:
如果 a = -19,b = 5
那么 q = -4, r = 1
-19 = 5 x -4 + 1
商余定理的使用:
商余数定理是模运算中的基本定理。它用于证明模加法、模乘法和模算术中的更多原理。
证明:
To prove Quotient Remainder theorem, we have to prove two things:
For any integer a and positive integer b:
1. q and r exist
2. q and r are unique
Existence of q and r:
Consider the progression …, a – 3b, a – 2b, a – b, a, a + b, a + 2b, a + 3b…
This extends in both directions.
By the Well-Ordering Principle, there must exist a smallest non-negative element x.
Thus, x = a – qb and x must be in the interval [0, b) because otherwise r-b would be smaller than r and a non-negative element in the progression.
Uniqueness of q and r:
Suppose we have another pair q0 and r0 such that a =b x q0 + r0, with 0 <= r0 < b.
b x q + r = b x q0 + r0
We see that r – r0 = b(q0 – q), and so q0 – q = b / (r – r0)
Since 0 <= r < b and 0 <= r0 < b, we have that -b < r-r0 < b
Hence, r- r0 = 0 that implies r = r0
So r – r0 = 0 = b(q0 – q)
which implies that q = q0.
This shows uniqueness.