login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A046893 a(n) is the least number with exactly n permutations of digits that are primes. 1

%I #20 Feb 09 2023 21:55:25

%S 1,2,13,103,107,1007,1036,1019,1013,1049,1079,1237,10099,10013,10135,

%T 10123,10039,10127,10079,10238,10234,10235,10139,10478,12349,12347,

%U 10378,12359,14579,10789,100336,10237,12389,23579,10279,100136,12379,10379,100267,13789

%N a(n) is the least number with exactly n permutations of digits that are primes.

%C From _Robert Israel_, Feb 07 2023: (Start)

%C Permutations that have leading zeros are included, in contrast to A046890 where they are not.

%C If neither A046890(n) nor a(n) have the digit 0, then they are equal. (End)

%H Robert Israel, <a href="/A046893/b046893.txt">Table of n, a(n) for n = 0..1477</a>

%p g:= proc(d) local x,d1,y;

%p [seq(seq(seq(x*10^d + y, y = [0,h(x,d1)]),d1=0..d-1),x=1..9)]

%p end proc:

%p g(0):= [$0..9]:

%p h:= proc(x0, d) local y,z; option remember;

%p seq(seq(y*10^d+z, z = [procname(y,d-1)]),y=x0..9)

%p end proc:

%p for x0 from 1 to 9 do h(x0,0):= $x0 .. 9 od:

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

%p t:= 0;

%p L:= convert(n,base,10); d:= nops(L);

%p for P in combinat:-permute(L) do

%p if isprime(add(P[i]*10^(i-1),i=1..d)) then t:= t+1 fi

%p od;

%p t

%p end proc:

%p N:= 100: # for a(0)..a(N)

%p V:= Array(0..N): count:= 0:

%p for d from 0 while count < N+1 do

%p for i in g(d) while count < N+1 do

%p v:= f(i);

%p if v <= N then

%p if V[v] = 0 then V[v]:= i; count:= count+1; fi;

%p fi

%p od od:

%p convert(V,list); # _Robert Israel_, Feb 07 2023

%t a = Table[0, {40}]; Do[b = Count[ PrimeQ[ FromDigits /@ Permutations[ IntegerDigits[n]]], True]; If[b < 40 && a[[b + 1]] == 0, a[[b + 1]] = n; Print[b, " ", n]], {n, 1, 110000}]

%o (Python)

%o from sympy import isprime

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

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

%o def nd(d): yield from ("".join((f,)+m) for f in "123456789" for m in mc("0123456789", d-1))

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

%o def agen(): # generator of sequence terms

%o n, adict = 0, dict()

%o for digs in count(1):

%o for s in nd(digs):

%o v = c(s)

%o if v not in adict: adict[v] = int(s)

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

%o print(list(islice(agen(), 40))) # _Michael S. Branicky_, Feb 08 2023

%Y Cf. A039999, A046890. All terms are in A179239.

%K nonn,base,look

%O 0,2

%A _David W. Wilson_

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 16 18:22 EDT 2024. Contains 371750 sequences. (Running on oeis4.)