OFFSET
1,1
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 1..10000
EXAMPLE
The 5th prime 11 leads to 7 other primes: 13,17,19,31,41,61,71, hence a(5)=7.
a(6)=8, p=13, q={11,17,19,23,43,53,73,83}
a(7)=7, p=17, q={11,13,19,37,47,67,97}
a(8)=7, p=19, q={11,13,17,29,59,79,89}
a(9)=6, p=23, q={29,13,43,53,73,83}
a(10)=5, p=29, q={23,19,59,79,89}
MAPLE
A125002 := proc(n) local p, digs, res, r, d; p := ithprime(n) ; digs := convert(p, base, 10) ; res := 0 ; for d from 1 to nops(digs) do for r from 0 to 9 do if r <> op(d, digs) and ( d <> nops(digs) or r > 0) then q := p-(op(d, digs)-r)*10^(d-1) ; if isprime(q) then res := res+1 ; fi ; fi ; od ; od ; RETURN(res) ; end ; for n from 1 to 100 do printf("%d, ", A125002(n)) ; od ; # R. J. Mathar, Jan 13 2007
PROG
(Haskell)
import Data.List (delete)
a125002 n = sum $ map (a010051' . read) $
tail $ concatMap (f pds) [0 .. length pds - 1] where
pds = show $ a000040 n
f ws k = [us ++ [y] ++ vs |
let (us, v:vs) = splitAt k ws, y <- delete v "0123456789"]
-- Reinhard Zumkeller, Jul 06 2014
(Python)
from sympy import isprime, sieve
def neighbors(s):
digs = "0123456789"
ham1 = (s[:i]+d+s[i+1:] for i in range(len(s)) for d in digs if d!=s[i])
yield from (h for h in ham1 if h[0] != '0')
def a(n):
return sum(1 for s in neighbors(str(sieve[n])) if isprime(int(s)))
print([a(n) for n in range(1, 101)]) # Michael S. Branicky, May 09 2022
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Zak Seidov, Jan 08 2007
EXTENSIONS
Corrected and extended by Hans Havermann and R. J. Mathar, Jan 08 2007
STATUS
approved