Imagine we want to split chocolates for children so that each child receives chocolates and above chocolates at the end. If we have to , then those Remaining chocolates, we could get more chocolates and give one more to each child, which means that each child would receive chocolates, a contradiction. Soon we have proven that for positive values.
For negative values, this can be generalized as . The proof by contradiction would be similar to the previous one, where we could distribute a surplus of items of the supposed rest and changing the supposed quotient.
Then , soon , consequently and finally.
Now, on to your show.
First:
r = a - b*q;
Now, that is exactly what is in the above equation.
We can also deduce that if , then . If , then . This can be achieved by testing the four combinations of and (and also zero for ) that and with that that .
It can also be concluded from that , and with it .
So that we may have , it is because . And that’s where you come in if
.
Within the if
, we know that . So we have to . Since , then and with it .
Have the chance that is absurd because it would mean that , and the result of a module cannot be negative and the case of zero does not enter in this if
. So we have to and therefore .
If you don’t get on if
, own already ensures that because modules cannot be negative, and that condition also prevents you from reaching or exceeding the value of .
Unifying the cases where you enter or not if
, we have to .
The case where the module makes a difference within the if
that’s when and .
The value added to the rest within the if
is correct because by adding , It’s like pretending an extra chocolate was given to each child, which should make the resulting rest equal. As explained above, this does not violate the condition that , and in fact, it serves exactly to put the value of the rest in the expected range, and therefore everything is right.
Friend, it is difficult to understand what is your difficulty. What is "a new rest"? The sentence alone, the way it is, does not make sense. Edit the question and improve it, as it is not at all clear. Also explain if your problem is mathematical or programming.
– Luiz Vieira