Division Algorithm
Given two integers
function divide_unsigned(A,B)
if B = 0 then error(DivisionByZero) end
R := A
Q := 0
while R ≥ B do
R := R − B
Q := Q + 1
end
return (Q, R)
end
Proof
Existence
Suppose (without loss of generality) that
There exist integers
:
and :
and
Let
If
so
Then the algorithm for finding a minimal
- Start with
- Increment by 1 until
Uniqueness
Let
By definition,
Thus,
By definition,
Setting these equal to each other,
so
However, as established,
then, necessarily,
so
QED.