login
Primes with equal number of prime and nonprime digits.
3

%I #14 Apr 23 2024 08:10:48

%S 13,17,29,31,43,47,59,67,71,79,83,97,1033,1123,1153,1213,1217,1229,

%T 1231,1259,1279,1283,1297,1303,1307,1321,1367,1423,1427,1433,1453,

%U 1531,1543,1559,1567,1571,1579,1583,1597,1627,1637,1657,1721,1747,1759,1783,1787

%N Primes with equal number of prime and nonprime digits.

%C Prime digits are 2, 3, 5 or 7. Nonprime digits are 0, 1, 4, 6, 8 or 9.

%C Complement of (A154385 U A154386). [_Juri-Stepan Gerasimov_, Nov 29 2009]

%H Michael S. Branicky, <a href="/A156343/b156343.txt">Table of n, a(n) for n = 1..10000</a>

%e 13 (1=nonprime, 3=prime) = a(1).

%p A109066c := proc(n) nops(convert(n,base,10))-A109066(n) ; end:

%p A109066 := proc(n) local dgs,a ; dgs := convert(n,base,10) ; a := 0 ; for i in dgs do if isprime(i) then a := a+1 ; fi; od: a ; end:

%p for i from 1 to 400 do p := ithprime(i) ; if A109066(p) = A109066c(p) then printf("%d,",p) ; fi; od: # _R. J. Mathar_, Feb 09 2009

%t Select[Prime[Range[5,300]],Length[Select[IntegerDigits[#],PrimeQ]]==Length[ Select[ IntegerDigits[ #],!PrimeQ[ #]&]]&] (* _Harvey P. Dale_, Dec 15 2022 *)

%o (Python)

%o from sympy import isprime

%o def ok(n):

%o if not isprime(n): return False

%o s, counts = str(n), [0, 0]

%o for c in s: counts[int(c in "2357")] += 1

%o return counts[0] == counts[1]

%o print([k for k in range(10**4) if ok(k)]) # _Michael S. Branicky_, Apr 23 2024

%Y Cf. A000040, A154385, A154386, A371352.

%K nonn,base

%O 1,1

%A _Juri-Stepan Gerasimov_, Feb 08 2009