The OEIS mourns the passing of Jim Simons and is grateful to the Simons Foundation for its support of research in many branches of science, including the OEIS.
login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A283187 a(0) = 0; a(1) = 1; a(2*n) = 2*a(n), a(2*n+1) = a(n) + (-1)^a(n+1). 1
0, 1, 2, 2, 4, 3, 4, 3, 8, 3, 6, 4, 8, 3, 6, 4, 16, 7, 6, 4, 12, 7, 8, 5, 16, 7, 6, 4, 12, 7, 8, 5, 32, 15, 14, 8, 12, 7, 8, 5, 24, 11, 14, 8, 16, 7, 10, 6, 32, 15, 14, 8, 12, 7, 8, 5, 24, 11, 14, 8, 16, 7, 10, 6, 64, 31, 30, 16, 28, 15, 16, 9, 24, 11, 14, 8, 16, 7, 10, 6, 48, 23, 22, 12, 28, 15, 16, 9, 32, 15, 14 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,3
LINKS
EXAMPLE
a(0) = 0;
a(1) = 1;
a(2) = a(2*1) = 2*a(1) = 2*1 = 2;
a(3) = a(2*1+1) = a(1) + (-1)^a(2) = 1 + (-1)^2 = 2;
a(4) = a(2*2) = 2*a(2) = 2*2 = 4;
a(5) = a(2*2+1) = a(2) + (-1)^a(3) = 2 + (-1)^2 = 3, etc.
MATHEMATICA
a[0] = 0; a[1] = 1; a[n_] := If[EvenQ[n], 2 a[n/2], a[(n - 1)/2] + (-1)^a[(n + 1)/2]]; Table[a[n], {n, 0, 90}]
PROG
(PARI)
a(n) = if (n<2, n, if (n%2==0, 2*a(n/2), a((n-1)/2)+(-1)^(a(n+1)/2)));
tabl(nn)={for (n=0, nn, print1(a(n), ", "); ); };
tabl(90); \\ Indranil Ghosh, Mar 03 2017
(Python)
def a(n):
....if n==0 or n==1: return n
....if n%2==0: return 2*a(n/2)
....else: return a((n-1)/2)+(-1)**a((n+1)/2) # Indranil Ghosh, Mar 03 2017
(Python)
from functools import lru_cache
@lru_cache(maxsize=None)
def A283187(n): return n if n <= 1 else A283187(n//2) + (-1 if A283187((n+1)//2) % 2 else 1) if n % 2 else 2*A283187(n//2) # Chai Wah Wu, Mar 08 2022
CROSSREFS
Cf. A000079 (fixed points), A006165, A087808, A283165.
Sequence in context: A356148 A083742 A107331 * A324391 A357978 A087808
KEYWORD
nonn,hear
AUTHOR
Ilya Gutkovskiy, Mar 02 2017
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified June 12 01:17 EDT 2024. Contains 373320 sequences. (Running on oeis4.)