The following equation is used to find the inverse of the remainder. Suppose we have a whole number w
, which is divided by a natural number n
. We assume that the remainder is r
. Then the inverse i
is defined as:
i = (n - (w % n)) % n [equation 1] i = (n - r) % n [equation 2]
Thus, i
satisfies the following equation:
(w + i) % n = 0 [equation 3]
In words, it can be defined as:
The inverse of the remainder of a fractional number is smallest whole number which when added to the numerator makes it perfectly divisible by the denominator.
I'm currently using equation 1
in a program I'm writing to find the inverse of the remainder. However it doesn't seem like an elegant method to compute the inverse. Can the equation be simplified? Please give the steps to simplify the equation if possible.