OFFSET
1,2
COMMENTS
a(1) = 1 by convention.
The first binary home prime that is not known is a(2295). - Ely Golden, Jan 09 2017
LINKS
Ely Golden, Table of n, a(n) for n = 1..2294
Patrick De Geest, Home Primes
Ely Golden, Mersenne Wiki Home Primes base 2
Ely Golden, Table of n, a(n) for n = 1..3000 (a-file)
EXAMPLE
4 = 2*2 -> 1010 = 10 = 2*5 ->10101 = 21 = 3*7 -> 11111 = 31 = prime.
MATHEMATICA
f[n_] := Module[{fi}, If[PrimeQ[n], n, fi = FactorInteger[n]; Table[ First[#], {Last[#]}]& /@ fi // Flatten // IntegerDigits[#, 2]& // Flatten // FromDigits[#, 2]&]]; a[1] = 1; a[n_] := TimeConstrained[FixedPoint[f, n], 1] /. $Aborted -> -1; Array[a, 55] (* Jean-François Alcover, Jan 01 2016 *)
PROG
(SageMath)
def digitLen(x, n):
r=0
while(x>0):
x//=n
r+=1
return r
def concatPf(x, n):
r=0
f=list(factor(x))
for c in range(len(f)):
for d in range(f[c][1]):
r*=(n**digitLen(f[c][0], n))
r+=f[c][0]
return r
def hp(x, n):
x1=concatPf(x, n)
while(x1!=x):
x=x1
x1=concatPf(x1, n)
return x
radix=2
index=2
while(index<=1344):
print(str(index)+" "+str(hp(index, radix)))
index+=1
(Python)
from sympy import factorint, isprime
def f(n):
if n == 1: return 1
return int("".join(bin(p)[2:]*e for p, e in factorint(n).items()), 2)
def a(n):
if n == 1: return 1
while not isprime(n): n = f(n)
return n
print([a(n) for n in range(1, 56)]) # Michael S. Branicky, Oct 07 2022
CROSSREFS
KEYWORD
nonn,base,nice
AUTHOR
Michael B Greenwald (mbgreen(AT)central.cis.upenn.edu)
STATUS
approved