OFFSET
1,1
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..10000
EXAMPLE
a(13) = 83 as prime(13) = 41 and 83 == 1 (mod 41). 83 is the largest such two-digit prime.
MAPLE
A055642 := proc(n) max(1, ilog10(n)+1) ; end: A109938 := proc(n) local p, k, a; p := ithprime(n) ; k := A055642(p) ; a := 0; q := numtheory[pi](10^(k-1)) ; q := ithprime(q+1) ; while A055642(q) < k+1 do if q mod p = 1 and q > a then a := q ; fi ; q := nextprime(q) ; od ; RETURN(a) ; end: seq(A109938(n), n=1..90) ; # R. J. Mathar, Aug 17 2007
PROG
(Python)
from sympy import prime, prevprime
def a(n):
pn = prime(n); k = len(str(pn))
p = prevprime(10**k); lb = max(10**(k-1), 2)
while p > lb and p%pn != 1: p = prevprime(p)
return p if p > lb else 0
print([a(n) for n in range(1, 81)]) # Michael S. Branicky, Jul 07 2021
(Python) # faster version for initial segment of sequence
from sympy import prime, primerange
def aupto(limit):
alst, primeswithkdigs, plimit = [], dict(), prime(limit)
for k in range(1, len(str(plimit))+1):
primeswithkdigs[k] = list(primerange(10**(k-1), 10**k))[::-1]
for pn in primerange(1, plimit+1):
k, found = len(str(pn)), False
for pk in primeswithkdigs[k]:
if pk%pn == 1: alst.append(pk); found = True; break
if not found: alst.append(0)
return alst
print(aupto(80)) # Michael S. Branicky, Jul 07 2021
CROSSREFS
KEYWORD
base,nonn
AUTHOR
Amarnath Murthy, Jul 19 2005
EXTENSIONS
More terms from R. J. Mathar, Aug 17 2007
STATUS
approved