OFFSET
1,2
LINKS
Vincenzo Librandi, Table of n, a(n) for n = 1..1000
FORMULA
a(1)=1, a(2)=4; a(n) = 16*a(floor(n/2))+1 for n odd, otherwise a(n) = 16*a(floor((n-1)/2))+4. - Bruno Berselli, May 28 2012
MATHEMATICA
FromDigits[#, 16]&/@Flatten[Table[Tuples[{1, 4}, n], {n, 5}], 1] (* Harvey P. Dale, Feb 02 2012 *)
PROG
(Magma) [n: n in [1..75000] | Set(IntegerToSequence(n, 16)) subset {1, 4}]; // Vincenzo Librandi, May 28 2012
(Maxima) a[1]:1$ a[2]:4$ a[n]:= if oddp(n) then 16*a[floor(n/2)]+1 else 16*a[floor((n-1)/2)]+4$ makelist(a[n], n, 1, 37); /* Bruno Berselli, May 28 2012 */
(Python)
def a(n): return int(bin(n+1)[3:].replace('1', '4').replace('0', '1'), 16)
print([a(n) for n in range(1, 38)]) # Michael S. Branicky, Aug 22 2021
CROSSREFS
KEYWORD
nonn,base,easy
AUTHOR
STATUS
approved