For a given integer $x>0$, I need to find all integers $a \in [0, 10^{15}]$ which have the following property: the digit sum of $a$ equals the digit sum of $x\cdot a$. I found this link <http://mathworld.wolfram.com/CastingOutNines.html> which looks quite relevant to my task, but I can't figure out how to apply it. Any ideas?