[go: up one dir, main page]

login
A158124
Weakly prime numbers (or isolated primes): changing any one decimal digit always produces a composite number, with restriction that first digit may not be changed to a 0.
9
294001, 505447, 584141, 604171, 929573, 971767, 1062599, 1282529, 1524181, 2017963, 2474431, 2690201, 3070663, 3085553, 3326489, 4393139, 5152507, 5285767, 5564453, 5575259, 5974249, 6173731, 6191371, 6236179, 6463267, 6712591, 7204777, 7469789, 7469797, 7810223
OFFSET
1,1
COMMENTS
The definition could be restated as "primes p with d digits such that there is no prime q with at most d digits at Hamming distance 1 from p (in base 10)". - N. J. A. Sloane, May 06 2019
For the following values of k, 5, 6, 7, 8, 9, 10, the number of terms < 10^k in this sequence is 0, 6, 43, 406, 3756, 37300. - Jean-Marc Rebert, Nov 10 2015
LINKS
C. Rivera, Weakly Primes
Eric Weisstein's World of Mathematics, Weakly Prime
MAPLE
filter:= proc(n)
local L, i, d, ds;
if not isprime(n) then return false fi;
L:= convert(n, base, 10);
for i from 1 to nops(L) do
if i = nops(L) then ds:= {$1..9} minus {L[i]}
elif i = 1 then ds:= {1, 3, 7, 9} minus {L[i]}
else ds:= {$0..9} minus {L[i]}
fi;
for d in ds do
if isprime(n + (d - L[i])*10^(i-1)) then return false fi;
od
od;
true
end proc:
select(filter, [seq(i, i=11..10^6, 2)]); # Robert Israel, Dec 15 2015
MATHEMATICA
Select[Prime@ Range[10^5], Function[n, Function[w, Total@ Map[Boole@ PrimeQ@ # &, DeleteCases[#, n]] &@ Union@ Flatten@ Map[Function[d, FromDigits@ ReplacePart[w, d -> #] & /@ If[d == 1, #, Prepend[#, 0]] &@ Range@ 9], Range@ Length@ w] == 0]@ IntegerDigits@ n]] (* Michael De Vlieger, Dec 13 2016 *)
PROG
(PARI) isokp(n) = {v = digits(n); for (k=1, #v, w = v; if (k==1, idep = 1, idep=0); for (j=idep, 9, if (j != v[k], w[k] = j; ntest = subst(Pol(w), x, 10); if (isprime(ntest), return(0)); ); ); ); return (1); }
lista(nn) = {forprime(p=2, nn, if (isokp(p), print1(p, ", ")); ); } \\ Michel Marcus, Dec 15 2015
(Python)
from sympy import isprime
def h1(n): # hamming distance 1 neighbors of n, not starting with 0
s = str(n); d = "0123456789"; L = len(s)
yield from (int(s[:i]+c+s[i+1:]) for c in d for i in range(L) if c!=s[i] and not (i==0 and c=="0"))
def ok(n): return isprime(n) and all(not isprime(k) for k in h1(n))
print([k for k in range(10**6) if ok(k)]) # Michael S. Branicky, Jul 31 2022
CROSSREFS
Cf. A050249, A158125 (weakly primes), A186995, A192545.
Sequence in context: A255754 A254843 A318787 * A050249 A354440 A224973
KEYWORD
nonn,base
AUTHOR
Eric W. Weisstein, Mar 13 2009
EXTENSIONS
Edited by Charles R Greathouse IV, Aug 02 2010
Missing a(3385) inserted into b-file by Andrew Howroyd, Feb 23 2018
STATUS
approved