login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A249448
Largest n-digit prime whose digit sum is also prime.
3
7, 89, 991, 9967, 99991, 999983, 9999971, 99999989, 999999937, 9999999943, 99999999821, 999999999989, 9999999999971, 99999999999923, 999999999999883, 9999999999999851, 99999999999999997, 999999999999999967, 9999999999999999919, 99999999999999999989, 999999999999999999829
OFFSET
1,1
COMMENTS
Subsequence of A046704 (primes with digit sum being prime).
Some terms of this sequence are also in A003618, the largest n-digit primes.
LINKS
EXAMPLE
a(1) = 7 because it is the largest prime with just one digit.
a(2) = 89 because it is the largest prime with 2 digits whose sum, 8 + 9 = 17, is a prime.
Again, a(7) = 9999971 because it is the largest prime with 7 digits whose sum is a prime: 9 + 9 + 9 + 9 + 9 + 7 + 1 = 53.
MAPLE
P:=proc(q) local a, b, k, n; for k from 0 to q do
for n from 10^(k+1)-1 by -1 to 10^k do if isprime(n) then a:=n; b:=0;
while a>0 do b:=b+(a mod 10); a:=trunc(a/10); od;
if isprime(b) then print(n); break; fi; fi;
od; od; end: P(10^3);
MATHEMATICA
Table[Module[{p=NextPrime[10^n, -1]}, While[!PrimeQ[Total[IntegerDigits[p]]], p=NextPrime[p, -1]]; p], {n, 25}] (* Harvey P. Dale, Jun 20 2023 *)
PROG
(PARI) a(n) = {p = precprime(10^n); while (!isprime(sumdigits(p)), p = precprime(p-1)); p; } \\ Michel Marcus, Oct 29 2014
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Paolo P. Lava, Oct 29 2014
STATUS
approved