A193890 Primes p such that replacing any single decimal digit d with 3*d produces another prime (obviously p can contain only digits 0, 1, 2 or 3).
11, 311, 1301, 10133, 1030031
Offset: 1
Examples
1301 belongs to this sequence because 1303, 1301, 1901 and 3301 are all prime.
Links
- G. L. Honaker, Jr. and Chris Caldwell, Prime Curios! 1030031
- The Prime Puzzles and Problems Connection, Puzzle 822
Programs
-
Haskell
import Data.List (inits, tails) a193890 n = a193890_list !! (n-1) a193890_list = filter f a107715_list where f n = (all ((== 1) . a010051) $ zipWith (\ins (t:tns) -> read $ (ins ++ x3 t ++ tns)) (init $ inits $ show n) (init $ tails $ show n)) where x3 '0' = "0" x3 '1' = "3" x3 '2' = "6" x3 '3' = "9" -- Reinhard Zumkeller, Aug 11 2011
-
Maple
S:= NULL: for x from 2 to 3^10 do L:= convert(x, base, 3): if numboccur(1,L) mod 3 <> 2 then next fi; L1:= subs(2=3,L); L2:= subs(1=2,L1); for LL in [L1,L2] do y:= add(LL[i]*10^(i-1), i=1..nops(L1)); if isprime(y) then good:= true; for j from 1 to nops(LL) do yp:= y + 2*LL[j]*10^(j-1); if not isprime(yp) then good:= false; break fi od: if good then S:= S, y fi; fi; od od: sort([S]); # Robert Israel, Mar 07 2016
-
Mathematica
Select[Select[Prime@ Range[10^6], AllTrue[IntegerDigits@ #, MemberQ[{0, 1, 2, 3}, #] &] &], Function[k, AllTrue[Map[FromDigits, Map[MapAt[3 # &, IntegerDigits@ k, #] &, Range@ IntegerLength@ k]], PrimeQ]]] (* Michael De Vlieger, Mar 06 2016, Version 10 *)
-
Python
from sympy import isprime from itertools import product A193890_list = [] for l in range(1,10): for d in product('0123',repeat=l): p = int(''.join(d)) if d[0] != '0' and d[-1] in ('1','3') and isprime(p): for i in range(len(d)): d2 = list(d) d2[i] = str(3*int(d[i])) if not isprime(int(''.join(d2))): break else: A193890_list.append(p) # Chai Wah Wu, Aug 13 2015
Comments