Generate the sequence a(n) when each element is the minimum integer multiple m such that the digit sum of n times m is equal to n.



Task
 Find the first 40 elements of the sequence.


Stretch
 Find the next 30 elements of the sequence.


See also
 OEIS:A131382 - Minimal number m such that Sum_digits(n*m)=n




/* this is very slow even in emulation - if you're going to try it
 * on a real 8-bit micro I'd recommend setting this back to 40;
 * it does, however, eventually get there */
byte MAX = 70;
 
/* note on types: 2^32 is a 10-digit number,
 * so the digit sum of an ulong is guaranteed
 * to be <= 90 */
proc nonrec digitsum(ulong n) byte:
    byte sum;
    sum := 0;
    while n /= 0 do
        sum := sum + make(n % 10, byte);
        n := n / 10
    od;
    sum
corp
 
proc nonrec a131382(ulong n) ulong:
    ulong m;
    m := 1;
    while digitsum(m * n) /= n do
        m := m + 1
    od;
    m
corp
 
proc nonrec main() void:
    byte n;
    for n from 1 upto MAX do
        write(a131382(n):9);
        if (n & 7) = 0 then writeln() fi
    od
corp