OFFSET
0,3
LINKS
FORMULA
a(0) = 0, a(1) = 1, for n > 0 a(2*n) = 2*a(n) + [a(n) even], a(2*n + 1) = 2*a(n) + [a(n) odd]. - Yosu Yurramendi, May 23 2020
MAPLE
a:= proc(n) option remember; `if`(n<2, n, (m->
2*m+1-irem(m+n, 2))(a(iquo(n, 2))))
end:
seq(a(n), n=0..72); # Alois P. Heinz, May 29 2021
MATHEMATICA
a[0] = 0; a[1] = 1; a[n_] := a[n] = 2 # + 1 - Mod[Mod[n, 2] + Mod[#, 2], 2] &@ a[Floor[n/2]]; Table[a@ n, {n, 0, 72}] (* Michael De Vlieger, Apr 02 2017 *)
PROG
(PARI) a(n) = if(n<2, n, my(m=a(n\2)); 2*m + 1 - (n%2 + m%2)%2); \\ Indranil Ghosh, Apr 05 2017
(Python)
def a(n):
if n<2:return n
else:
m=a(n//2)
return 2*m + 1 - (n%2 + m%2)%2 # Indranil Ghosh, Apr 05 2017
(C)
#include <stdio.h>
int a(int n){
int m;
if (n<2){return n; }
else{
m=a(n/2);
return 2*m + 1 - (n%2 + m%2)%2;
}
}
int main()
{
int n=0;
for(; n<=100; n++)
printf("%d, ", a(n));
return 0;
} /* Indranil Ghosh, Apr 05 2017 */
(R)
maxn <- 63 # by choice
a <- 1
for(n in 1:maxn){
a[2*n ] <- 2*a[n] + (a[n]%%2 == 0)
a[2*n+1] <- 2*a[n] + (a[n]%%2 != 0)}
a <- c(0, a)
# Yosu Yurramendi, May 23 2020
CROSSREFS
KEYWORD
nonn,look
AUTHOR
Reinhard Zumkeller, Aug 15 2010
EXTENSIONS
Name edited by Jon E. Schoenfield, Apr 05 2017
STATUS
approved