login
Least n-digit zeroless prime with nonprime digits.
2

%I #16 Aug 20 2022 13:38:05

%S 11,149,1181,11119,111119,1111169,11111119,111111181,1111111181,

%T 11111111449,111111111149,1111111111441,11111111111411,

%U 111111111111691,1111111111111181,11111111111111119,111111111111111161

%N Least n-digit zeroless prime with nonprime digits.

%H Robert Israel, <a href="/A103544/b103544.txt">Table of n, a(n) for n = 2..999</a>

%p f:= proc(n) local t,x,L,y;

%p t:= (10^n-1)/9;

%p for x from 0 to 5^n-1 do

%p L:= subs({1=3, 2=5, 3=7, 4=8},convert(x,base,5));

%p y:= t+add(10^(i-1)*L[i],i=1..nops(L));

%p if isprime(y) then return y fi

%p od;

%p FAIL

%p end proc:

%p map(f, [$2..20]); # _Robert Israel_, Sep 28 2018

%t NextPrim[n_] := Block[{k = n + 1}, While[ !PrimeQ[k], k++ ]; k]; f[n_] := Block[{np = NextPrim[(10^n - 1)/9 - 1]}, While[ Union[ Join[{1, 4, 6, 8, 9}, IntegerDigits[np]]] != {1, 4, 6, 8, 9}, np = NextPrim[np]]; np]; Table[ f[n], {n, 2, 18}] (* _Robert G. Wilson v_, Mar 23 2005 *)

%t ndzp[n_]:=Module[{np=NextPrime[FromDigits[PadRight[{},n,1]]]},While[ !SubsetQ[ {1,4,6,8,9},IntegerDigits[ np]],np =NextPrime[np]];np]; Join[{11},Array[ndzp,16,3]] (* _Harvey P. Dale_, Aug 28 2021 *)

%o (Python)

%o from sympy import isprime

%o from itertools import product

%o def a(n):

%o for p in product("14689", repeat=n):

%o t = int("".join(p))

%o if isprime(t): return t

%o print([a(n) for n in range(2, 22)]) # _Michael S. Branicky_, Aug 20 2022

%K base,nonn

%O 2,1

%A _Ray G. Opao_, Mar 22 2005

%E More terms from _Robert G. Wilson v_, Mar 23 2005