login
Number of n-digit primes in which n-1 of the digits are 9's.
12

%I #33 Mar 02 2019 23:29:32

%S 4,6,7,7,8,10,7,13,8,8,11,13,8,11,13,14,10,9,7,11,9,13,10,19,5,10,14,

%T 7,10,9,9,15,13,8,7,9,10,11,10,13,5,12,15,7,12,7,12,11,13,11,8,13,13,

%U 13,12,12,9,9,15,14,9,8,13,11,15,17,10,8,11,10,6,16,8,8,8,15,9,11,14,7,10,11,16,17,11,10,12,16,8,15,7,11,11,10,7,12,6,10,8,9

%N Number of n-digit primes in which n-1 of the digits are 9's.

%C The other digit cannot be 0, 3, 6, or 9, or else the number would not be prime. - _N. J. A. Sloane_, May 20 2016

%H Dana Jacobsen, <a href="/A266148/b266148.txt">Table of n, a(n) for n = 1..2500</a> (first 1215 terms from Michael De Vlieger and Robert G. Wilson v)

%e a(3) = 7 since 199, 499, 599, 919, 929, 991 and 997 are all the three-digit primes containing two 9's.

%t f9[n_] := Block[{cnt = k = 0, r = 9 (10^n - 1)/9, s = Range[0, 9] - 9}, While[k < n, cnt += Length@ Select[r + 10^k * s, PrimeQ@ # && IntegerLength@ # > k &]; k++]; cnt]; Array[f9, 100]

%o (Python)

%o from sympy import isprime

%o def A266148(n):

%o return sum(1 for d in range(-9,1) for i in range(n) if isprime(10**n-1+d*10**i)) # _Chai Wah Wu_, Dec 31 2015

%o (Perl) use ntheory ":all"; sub a266148 { my $n = shift; vecsum( map { my $k=$_; scalar grep { is_prime("9" x $k . $_ . "9" x ($n-$k-1)) } 0+($k>0) .. 8 } 0 .. $n-1 ); } # _Dana Jacobsen_, Jan 01 2016

%Y Cf. A265733, A266141, A266142, A266143, A266144, A266145, A266146, A266147, A266149, A095714, A089675.

%K base,nonn

%O 1,1

%A _Michael De Vlieger_ and _Robert G. Wilson v_, Dec 21 2015