Calculating number which is divisible by a given number, knowing only pieces of the number

68 Views Asked by At

I'm given a number 'C' in a known base, and the first few digits 'D' (rightmost) of the other number, in the same base. I'm also told that a certain number of a digit 'E' can be appended to the end of the number (on the left). Given all this information, is there any way to know how many of the digit needs to be appended in order to get a number that is divisible by 'C' without actually having to append 'E' to 'D' until I arrive at such a value?

For instance, given:

Base = 5 C = 43 (in base 5, 23 in base 10), D = 412 (in base 5, 107 in base 10), E = 4 (in base 5, 4 in base 10 as well)

Instead of repeatedly testing like: 412/43, 4412/43, 44412/43, 444412/43....

Is there any way to instantly know how many 4's I'd need to add?