OFFSET
1,2
COMMENTS
a(n) is the largest prime whose binary expansion is an initial substring of n's binary expansion. - Charlie Neder, Oct 27 2018
a(1) = 1 by convention. - David A. Corneth, Oct 27 2018
LINKS
Reinhard Zumkeller, Table of n, a(n) for n = 1..10000
MATHEMATICA
ner[ n_Integer ] := FixedPoint[ If[ EvenQ[ # ]&&#>2, #/2, If[ PrimeQ[ # ]||(#=== 1), #, (#-1)/2 ] ]&, n, 20 ]
PROG
(Haskell)
a039634 1 = 1
a039634 n = until ((== 1) . a010051) (flip div 2) n
-- Reinhard Zumkeller, Nov 17 2013
(PARI) a(n)=while(n>3 && !isprime(n), n\=2); n \\ Charles R Greathouse IV, Jun 23 2017
(Python)
from sympy import isprime
def a(n):
while n>1 and not isprime(n): n>>=1
return n
print([a(n) for n in range(1, 82)]) # Michael S. Branicky, Jul 24 2023
CROSSREFS
KEYWORD
nonn,easy,nice
AUTHOR
EXTENSIONS
Offset corrected by Reinhard Zumkeller, Nov 17 2013
STATUS
approved