cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A209252 Number of primes (excluding n) that may be generated by replacing any decimal digit of n with a digit from 0 to 9.

This page as a plain text file.
%I A209252 #45 Apr 23 2025 02:38:19
%S A209252 4,4,3,3,4,3,4,3,4,4,4,7,5,9,4,5,4,8,4,7,2,7,3,7,2,3,2,8,2,5,2,5,3,9,
%T A209252 2,3,2,6,2,7,3,6,4,8,3,4,3,7,3,8,2,7,3,7,2,3,2,8,2,5,2,5,3,9,2,3,2,6,
%U A209252 2,7,3,6,4,8,3,4,3,9,3,6,2,7,3,7,2,3,2,8,2,5,1,6,2,8,1,2,1,5,1,6,4,10,5,9,4
%N A209252 Number of primes (excluding n) that may be generated by replacing any decimal digit of n with a digit from 0 to 9.
%C A209252 I expect that the average value of a(n) is 45/log 100 if n is coprime to 10 and 0 otherwise. - _Charles R Greathouse IV_, Jan 14 2013
%C A209252 First occurrence of k = 0..27: 200, 90, 20, 2, 1, 12, 37, 11, 17, 13, 101, 109, 107, 177, 357, 1001, 1011, 10759, 13299, 11487, 42189, 113183, 984417, 344253, 1851759, 4787769, 16121457, 15848679. - _Robert G. Wilson v_, Dec 19 2015
%C A209252 The number of prime neighbors of n in H(A055642(n), 10), where H(k,b) is the Hamming graph whose vertices are the sequences of length k over the alphabet {0,1,...,b-1} with adjacency being defined by having Hamming distance 1 (see A158576). - _Michael S. Branicky_, Apr 22 2025
%H A209252 Michel Lagneau, <a href="/A209252/b209252.txt">Table of n, a(n) for n = 0..10000</a>
%H A209252 Terence Tao, <a href="http://arxiv.org/abs/0802.3361">A remark on primality testing and decimal expansions</a>, Journal of the Australian Mathematical Society 91:3 (2011), pp. 405-413.
%e A209252 a(0) = 4 because by replacing the digit 0, we obtain the 4 primes 2, 3, 5 and 7;
%e A209252 a(11) = 7 because by replacing the 1st digit of *1, we obtain the primes 31, 41, 61, 71, and by replacing the 2nd digit of 1* we obtain the primes 13, 17, 19, hence a(11) = 7.
%e A209252 a(13) = 8 because 03, 11, 17, 19, 23, 43, 53, 73 and 83 are all primes.
%e A209252 a(204) = 0 because it is impossible to find a prime number if we replace the digits 2, 0 or 4.
%p A209252 A209252 := proc(n)
%p A209252     local a,dgs,d,r,pd,p ;
%p A209252     a := 0 ;
%p A209252     dgs := convert(n,base,10) ;
%p A209252     for d from 1 to nops(dgs) do
%p A209252         for r from 0 to 9 do
%p A209252             pd := subsop(d=r,dgs) ;
%p A209252             p := add(op(i,pd)*10^(i-1),i=1..nops(pd)) ;
%p A209252             if isprime(p) and p <> n then
%p A209252                 a := a+1 ;
%p A209252             end if;
%p A209252         end do:
%p A209252     end do:
%p A209252     a ;
%p A209252 end proc: # _R. J. Mathar_, Jan 18 2013
%t A209252 f[n_] := Block[{c = k = 0, d, p, lmt = 1 + Floor@ Log10@ n}, While[k < lmt, d = 0; While[d < 10, p = Quotient[n, 10^(k+1)]*10^(k+1) + d*10^k + Mod[n, 10^k]; If[p != n && PrimeQ@ p, c++]; d++]; k++]; c]; f[0] = 4; Array[f, 105, 0] (* _Robert G. Wilson v_, Dec 19 2015 *)
%o A209252 (Python)
%o A209252 from sympy import isprime
%o A209252 def A209252(n):
%o A209252     return len([1 for i in range(len(str(n))) for d in '0123456789' if d != str(n)[i] and isprime(int(str(n)[:i]+d+str(n)[i+1:]))]) # _Chai Wah Wu_, Sep 19 2016
%o A209252 (Python)
%o A209252 from gmpy2 import digits, is_prime
%o A209252 def a(n):
%o A209252     s, c = list(map(int, digits(n))), 0
%o A209252     if len(s) > 1 and s[-1] not in {1, 3, 7, 9}:
%o A209252         z = int(is_prime(s[-1])) if all(c == 0 for c in s[1:-1]) else 0
%o A209252         return z + sum(1 for e in {1, 3, 7, 9} if is_prime(n + e - s[-1]))
%o A209252     for i in range(len(s)):
%o A209252         b = 10**(len(s)-1-i)
%o A209252         for j in range(10):
%o A209252             if j != s[i]:
%o A209252                 t = n + (j-s[i])*b
%o A209252                 if is_prime(t):
%o A209252                     c += 1
%o A209252     return c
%o A209252 print([a(n) for n in range(100)]) # _Michael S. Branicky_, Apr 22 2025
%Y A209252 Cf. A000040, A055642, A158576.
%K A209252 nonn,base
%O A209252 0,1
%A A209252 _Michel Lagneau_, Jan 14 2013