login
a(n) is the least positive integer that has exactly n anagrams that are semiprimes, or -1 if there is no such integer.
1

%I #22 Jun 14 2023 10:34:53

%S 1,4,15,123,129,134,178,1025,1148,1147,1137,1145,1349,1348,1357,10145,

%T 3589,10258,10137,10123,11269,10289,10268,10247,10235,10267,10234,

%U 10789,10279,11378,10378,12369,10349,10358,12368,10357,12689,12358,10459,12379,12679,13489,12346,12349,16789,12479

%N a(n) is the least positive integer that has exactly n anagrams that are semiprimes, or -1 if there is no such integer.

%C a(n) is the least k such that A131371(k) = n.

%C Leading zeros are not allowed.

%H Robert Israel, <a href="/A362499/b362499.txt">Table of n, a(n) for n = 0..1000</a>

%e a(3) = 123 because 123 has 3 anagrams that are semiprimes, namely 123 = 3 * 41, 213 = 3 * 71, and 321 = 3 * 107, and no smaller number works.

%p g:= proc(s,m) local t;

%p if s[1..m-1] = [0$(m-1)] then op(map(t -> [t,op(s)],[0,$(max(s) ..9)]))

%p else op(map(t -> [t,op(s)], [$(max(s) .. 9)]))

%p fi

%p end proc:

%p f:= proc(L,m) local P,t,i;

%p P:= select(t -> t[-1] <> 0 and numtheory:-bigomega(add(t[i]*10^(i-1), i=1..m))=2, combinat:-permute(L));

%p nops(P)

%p end proc:

%p V:= Array(0..100):

%p count:= 2: V[0]:= 1: V[1]:= 4:

%p L:= [seq(seq([b,a],b=[0,$a..9]),a=1..9)]:

%p for m from 2 while count < 101 do

%p for s in L while count < 101 do

%p v:= f(s,m);

%p if v <= 100 and V[v] = 0 then

%p V[v]:= add(s[i]*10^(i-1),i=1..m); count:= count+1;

%p fi

%p od;

%p L:= map(g, L, m)

%p od:

%p convert(V,list);

%o (Python)

%o from sympy import factorint

%o from sympy.utilities.iterables import multiset_permutations as mp

%o from itertools import count, islice, combinations_with_replacement as mc

%o def ndgen():

%o yield from ((f,)+r for d in count(1) for f in "123456789" for r in mc("0123456789", d-1))

%o def c(n): # is_semiprime

%o return sum(factorint(n).values()) == 2

%o def f(digs):

%o return sum(1 for p in mp(digs) if p[0]!="0" and c(t:=int("".join(p))))

%o def agen(): # generator of terms

%o adict, n = dict(), 0

%o for t in ndgen():

%o v = f(t)

%o if v not in adict: adict[v] = int("".join(t))

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

%o print(list(islice(agen(), 46))) # _Michael S. Branicky_, Jun 12 2023

%Y Cf. A131371, A001358.

%K nonn,base,look

%O 0,2

%A _Robert Israel_, Jun 11 2023