%I #26 Oct 07 2022 20:35:39
%S 1,2,3,31,5,11,7,179,29,31,11,43,13,23,29,12007,17,47,19,251,31,43,23,
%T 499,4091,4091,127,4091,29,127,31,1564237,59,4079,47,367,37,83,61,383,
%U 41,179,43,499,4091,4091,47,683,127,173,113,173,53,191,4091
%N Home primes in base 2: primes reached when you start with n and (working in base 2) concatenate its prime factors (A048985); repeat until a prime is reached (or -1 if no prime is ever reached). Answer is written in base 10.
%C a(1) = 1 by convention.
%C The first binary home prime that is not known is a(2295). - _Ely Golden_, Jan 09 2017
%H Ely Golden, <a href="/A048986/b048986.txt">Table of n, a(n) for n = 1..2294</a>
%H Patrick De Geest, <a href="http://www.worldofnumbers.com/topic1.htm">Home Primes</a>
%H Ely Golden, <a href="http://www.mersennewiki.org/index.php/Base_2_Home_Prime_Results">Mersenne Wiki Home Primes base 2</a>
%H Ely Golden, <a href="/A048986/a048986_2.txt">Table of n, a(n) for n = 1..3000 (a-file)</a>
%e 4 = 2*2 -> 1010 = 10 = 2*5 ->10101 = 21 = 3*7 -> 11111 = 31 = prime.
%t 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 *)
%o (SageMath)
%o def digitLen(x,n):
%o r=0
%o while(x>0):
%o x//=n
%o r+=1
%o return r
%o def concatPf(x,n):
%o r=0
%o f=list(factor(x))
%o for c in range(len(f)):
%o for d in range(f[c][1]):
%o r*=(n**digitLen(f[c][0],n))
%o r+=f[c][0]
%o return r
%o def hp(x,n):
%o x1=concatPf(x,n)
%o while(x1!=x):
%o x=x1
%o x1=concatPf(x1,n)
%o return x
%o radix=2
%o index=2
%o while(index<=1344):
%o print(str(index)+" "+str(hp(index,radix)))
%o index+=1
%o (Python)
%o from sympy import factorint, isprime
%o def f(n):
%o if n == 1: return 1
%o return int("".join(bin(p)[2:]*e for p, e in factorint(n).items()), 2)
%o def a(n):
%o if n == 1: return 1
%o while not isprime(n): n = f(n)
%o return n
%o print([a(n) for n in range(1, 56)]) # _Michael S. Branicky_, Oct 07 2022
%Y Cf. A048985, A037274, A049065.
%K nonn,base,nice
%O 1,2
%A Michael B Greenwald (mbgreen(AT)central.cis.upenn.edu)
|