login
a(n) is the smallest 7-smooth number ending with n, or -1 if there is none.
2

%I #12 Sep 22 2024 18:00:18

%S 10,1,2,3,4,5,6,7,8,9,10,-1,12,-1,14,15,16,-1,18,-1,20,21,13122,1323,

%T 24,25,126,27,28,729,30,-1,32,-1,1134,35,36,-1,7938,-1,40,441,42,243,

%U 144,45,2646,147,48,49,50,-1,252,-1,54,-1,56,-1,1458,-1,60,6561,162,63,64,-1,39366,567,168

%N a(n) is the smallest 7-smooth number ending with n, or -1 if there is none.

%H Robert Israel, <a href="/A376301/b376301.txt">Table of n, a(n) for n = 0..10000</a>

%e a(11) = -1 because no number ending in 11 is 7-smooth. See explanation at A376303.

%e a(22) = 13122 because 13122 = 2 * 3^8 is 7-smooth and ends in 22, and no smaller number works.

%p dmax:= 2: # for a(0) .. a(10^dmax - 1)

%p N:= 10^dmax-1: V:= Array(0..N,-1):

%p with(priqueue):

%p V[0]:= 10:

%p for d from 1 to dmax do

%p A:= Array(0..10^d-1,-1);

%p initialize(pq);

%p insert([-1,0,0,0,0],pq);

%p while pq[0] <> 0 do

%p t:= extract(pq);

%p x:= -t[1];

%p xd:= x mod 10^d;

%p if A[xd] = -1 then

%p A[xd]:= x;

%p insert([-7*x,t[2],t[3],t[4],t[5]+1],pq);

%p if t[5] = 0 then

%p insert([-5*x,t[2],t[3],t[4]+1,0],pq);

%p if t[4] = 0 then

%p insert([-3*x,t[2],t[3]+1,0,0],pq);

%p if t[3] = 0 then

%p insert([-2*x,t[2]+1,0,0,0],pq);

%p fi fi fi fi od;

%p V[10^(d-1) .. 10^d-1]:= A[10^(d-1) .. 10^d-1];

%p od:

%p convert(V,list);

%Y Cf. A002473, A085908, A376303.

%K sign,base

%O 0,1

%A _Robert Israel_, Sep 19 2024