login
Naughty primes: primes in which the number of zeros is greater than the number of all other digits.
9

%I #52 Apr 03 2023 10:36:11

%S 10007,10009,40009,70001,70003,70009,90001,90007,100003,200003,200009,

%T 300007,400009,500009,700001,900001,900007,1000003,1000033,1000037,

%U 1000039,1000081,1000099,1000303,1000403,1000409,1000507,1000609,1000907,1001003,1003001

%N Naughty primes: primes in which the number of zeros is greater than the number of all other digits.

%C a(31) = 1003001 is the smallest palindromic naughty prime. - _M. F. Hasler_, Nov 22 2009

%C This sequence can be considered as irregular table in which row n lists the terms with n digits. The row lengths (number of terms with n digits) are then 0, 0, 0, 0, 8, 9, 296, 275, 7934, 9527, 235729, ... - _M. F. Hasler_, Jul 13 2018

%H M. F. Hasler and Arkadiusz Wesolowski, <a href="/A164968/b164968.txt">Table of n, a(n) for n = 1..10000</a> (first 5000 terms from M. F. Hasler).

%H Chris Caldwell, The Prime Glossary, <a href="https://t5k.org/glossary/xpage/NaughtyPrime.html">Naughty prime</a>.

%e a(24) = 1000303 is a naughty prime because the number of zeros is greater than the number of all other digits.

%p Q[1]:= [seq([i],i=1..9)]:

%p for d from 2 to 6 do Q[d]:= map(t -> seq([i,op(t)],i=1..9),Q[d-1]) od:

%p F:= proc(d) local R,dn,s,sp,q,x;

%p R:= NULL;

%p for dn from 2 to floor((d-1)/2) do

%p for s in combinat:-choose([$1..d-2],dn-2) do

%p sp:= [0,op(s),d-1];

%p for q in Q[dn] do

%p x:= add(q[i]*10^sp[i],i=1..dn);

%p if isprime(x) then R:= R, x fi;

%p od od od;

%p sort([R])

%p end proc:

%p seq(op(F(d)),d=5..7); # _Robert Israel_, Jul 10 2018

%t lst = {}; Do[If[PrimeQ[n] && Count[IntegerDigits[n], 0] > IntegerLength[n]/2, AppendTo[lst, n]], {n, 10^4 + 1, 3^13, 2}]; lst (* _Arkadiusz Wesolowski_, Sep 18 2011 *)

%t Select[Prime[Range[100000]],DigitCount[#,10,0]>IntegerLength[#]/2&] (* _Harvey P. Dale_, Jun 09 2015 *)

%o (PARI) next_A164968(p)={ for( n=#Str(p)\2+1,oo, my(L=10^(2*n+1)); p=max(10^(2*n-3),p); while( L>p=nextprime(p+1), vecsort(Vecsmall(Str(p)))[n]>48 || return(p));p=0) } \\ _M. F. Hasler_, Nov 22 2009, syntax update Jul 10 2018

%o (PARI) A164968_row(n, a=List(), t=vectorv(n, i, 10^(n-i)))={for(z=2, (n-1)\2, my(v=vector(z, i, if(i<2, [1, 1], i<z, [2, n-1], [n, n]))); forvec(d=vector(z, i, [1, 9]), bittest(650, d[z])&& vecsum(d)%3&& forvec(p=v, isprime(d*vecextract(t, p))&& listput(a, d*vecextract(t, p)), 2))); Set(a)} \\ _M. F. Hasler_, Jul 13 2018

%o (Python)

%o from sympy import isprime

%o from itertools import combinations, count, islice, product

%o def agen(): # generator of terms

%o for d in count(5):

%o for first in "123456789":

%o passed = set()

%o for last in "1379":

%o for znum in range(d//2 + 1, d-1):

%o for zlocs in combinations(range(d-2), znum):

%o for rest in product("123456789", repeat=d-2-znum):

%o nzi, middle = 0, []

%o for i in range(d-2):

%o if i in zlocs:

%o middle.append("0")

%o else:

%o middle.append(rest[nzi])

%o nzi += 1

%o t = int("".join(first + "".join(middle) + last))

%o if isprime(t):

%o passed.add(t)

%o yield from sorted(passed)

%o print(list(islice(agen(), 31))) # _Michael S. Branicky_, Mar 11 2022

%K base,nonn

%O 1,1

%A _G. L. Honaker, Jr._, Sep 02 2009