Algorithm to add two digits to the end of a number to calculate a specific modulus

ibanmodulo

So, lets say I have a number 123456. 123456 % 97 = 72. How can I determine what two digits need to be added to the end of 123456 such that the new number % 97 = 1? Note–it must always be two digits.

For example, 12345676 % 97 = 1. In this case, I need to add the digits "76" to the end of the number.

(This is for IBAN number calculation.)

Best Solution

x = 123456

x = x * 100
newX = x + 1 + 97 - (x % 97)

Edit: put the 100 in the wrong place

Related Question