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.
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
Links
- Jean-Marc Rebert, Table of n, a(n) for n = 1..3756
- C. Rivera, Weakly Primes
- Eric Weisstein's World of Mathematics, Weakly Prime
Programs
-
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 *)
-
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
Extensions
Edited by Charles R Greathouse IV, Aug 02 2010
Missing a(3385) inserted into b-file by Andrew Howroyd, Feb 23 2018
Comments