login
a(n) is the greatest number with distinct decimal digits and n prime factors, counted with multiplicity, or -1 if there is no such number.
2

%I #14 Apr 05 2024 13:07:07

%S 1,987654103,987654301,9876541023,9876542103,9876543102,9876543201,

%T 9876543210,9876542130,9876543120,9876534120,9876345120,9876514032,

%U 9876431250,9876045312,9875324160,9876523104,9863147520,9875312640,9635217408,9845637120,9715064832,9574023168,9805234176,5892341760,6398410752,-1,-1,-1,536870912

%N a(n) is the greatest number with distinct decimal digits and n prime factors, counted with multiplicity, or -1 if there is no such number.

%C a(n) = -1 for n > 29.

%e a(2) = 987654301 = 486769*2029 has distinct digits and 2 prime factors counted with multiplicity, and is the largest such number.

%p N:= 29: V:= Array(0..N,-1):

%p for m from 10 to 1 by -1 do

%p for L in combinat:-permute([9,8,7,6,5,4,3,2,1,0],m) while count < N do

%p if L[1] = 0 then break fi;

%p x:= add(L[i]*10^(m-i),i=1..m);

%p v:= numtheory:-bigomega(x);

%p if v <= N and V[v] = -1 then V[v]:= x; count:= count+1 fi

%p od od:

%p convert(V,list);

%o (Python)

%o from sympy import primeomega

%o from itertools import count, islice, permutations as P

%o def agen(): # generator of terms

%o n, adict = 0, {0:1, 1:987654103, 2:987654301} # a(1), a(2) take a while

%o D = [p for d in range(10, 0, -1) for p in P("9876543210", d) if p[0] != "0"]

%o for k in (int("".join(t)) for t in D):

%o v = primeomega(k)

%o if v not in adict:

%o adict[v] = k

%o while n in adict: yield adict[n]; n += 1

%o yield from (adict[n] if n in adict else -1 for n in count(n))

%o print(list(islice(agen(), 19))) # _Michael S. Branicky_, Apr 05 2024

%Y Cf. A029743, A320969.

%K sign,base

%O 0,2

%A _Zak Seidov_ and _Robert Israel_, Jun 29 2023