# Sage code to compute sequence A004290 in the OEIS, by Eric M. Schmidt.
# I hereby waive all rights to this code, in accordance with the CC0
# waiver:
#
# http://creativecommons.org/publicdomain/zero/1.0/
#
# This code is based on C code by Rick Heylen found here
#
# http://www.mathpuzzle.com/Binary.html
# Compute smallest positive multiple of n whose base b representation
# has only 0's and 1's.
def minmulzo(n, b=10) :
if n==0 : return 0
pfrem = [-1] * n
m = 0
while pfrem[0] == -1:
for r in xrange(n) :
if pfrem[r] not in [-1,m] and pfrem[(r + b^m) % n] == -1 :
pfrem[(r + b^m) % n] = m
if pfrem[b^m % n] == -1 :
pfrem[b^m % n] = m
m += 1
res = 0
r = 0
while r > 0 or res == 0:
res += b^pfrem[r]
r = (r - b^pfrem[r]) % n
return res
[minmulzo(x) for x in [0..30]]