Finding the Correct number

91 Views Asked by At

I was going through my Highschool, Grade 9, Math Textbook today in my free time since I rarely get freely time in College. I found this question that I failed to answer and our teacher that time didn't discuss it.

The question was:

You are given two positive integers $d$ and $s$. Find the minimal positive integer $n$ which is divisible by $d$ and has the sum of digits equal to $s$.

Let's take $d=13$ and $s=50$, the answer should be $699998$. The answer was given the back of my book.

Is there a formula for doing this?