OFFSET
0,4
COMMENTS
Records occur for n: 1, 3, 8, 9, 45, 89, 99, 495, 998, ..., . [Robert G. Wilson v, Oct 04 2010]
LINKS
Robert G. Wilson v, Table of n, a(n) for n = 0..100000 (first 20000 terms and some terms up to 100000 from Victor Maslov)
Victor Maslov, Log-log plot for n = 0..20000
Project Euler, Problem 303: Multiples with small digits
FORMULA
If a(n)=k, then a(10n)=k. [Robert G. Wilson v, Oct 04 2010]
EXAMPLE
a(9)=1358 because 9*1358=12222 is the smallest multiple of 9 whose decimal digits are all 0, 1 or 2.
MATHEMATICA
f[n_] := Block[{id = {0, 1, 2}, k = 1}, While[ Union@ Join[id, IntegerDigits[k*n]] != id, k++ ]; k]; Array[f, 76] (* Robert G. Wilson v, Oct 04 2010 *)
PROG
(PARI) a(n)=my(k=n, t); while(1, t=vecsort(eval(Vec(Str(k))), , 8); if(t[#t]<3, return(k/n), k+=n)) \\ Charles R Greathouse IV, Sep 05 2011
(PARI) anydiggt2(n)=if(n<2, 0, while(n>0, if(n%10>2, return(1)); n\=10); 0)
a(n)={local(prd, ms=[], rems=[], msn, remsn, pow=10, maxm);
if(n<=0, return(0));
while(n%10==0, n\=10);
maxm=if(n%10==5, 5, if(n%2==1, 3, 4));
for(d=1, 9, if(!anydiggt2(prd=d*n), return(d));
if(prd%10<=2, ms=concat(ms, [d]); rems=concat(rems, [prd\10])));
while(1,
msn=listcreate(maxm*#ms); remsn=listcreate(maxm*#ms);
for(d=0, 9,
for(k=1, #ms,
if(!anydiggt2(prd=d*n+rems[k]), return(d*pow+ms[k]));
if(prd%10<=2, listput(msn, d*pow+ms[k]); listput(remsn, prd\10))));
ms=Vec(msn); rems=Vec(remsn); pow*=10; print1("."))}
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Herman Beeksma, Oct 01 2010
STATUS
approved