OFFSET
1,4
LINKS
Amiram Eldar, Table of n, a(n) for n = 1..10000
Benoit Cloitre, Graph of a(n) for n=1 up to 9
Benoit Cloitre, Graph of a(n) for n=1 up to 27
Benoit Cloitre, Graph of a(n) for n=1 up to 81
Benoit Cloitre, Graph of a(n) for n=1 up to 243
FORMULA
a(1) = 0 then a(n) = w(n) - a(n-w(n)) where w(n) = 3^floor(log(n-1)/log(3)).
a(3^n) = 0, a(3^n+1) = 3^n, a(3^n+2) = 3^n-1, a(3^n+3) = 3^n, etc.
a(n) = Sum_{i=1..n-1} (-1)^(i-1)*3^valuation(i, 3).
MATHEMATICA
a[n_] := Sum[(-1)^(i+1) * 3^IntegerExponent[i, 3], {i, 1, n-1}]; Array[a, 100] (* Amiram Eldar, Jun 17 2022 *)
PROG
(PARI) a(n)=if(n<2, 0, 3^floor(log(n-1)/log(3))-a(n-3^floor(log(n-1)/log(3))))
(PARI) a(n) = my(s=-1); fromdigits([if(d==1, s=-s) |d<-digits(n-1, 3)], 3); \\ Kevin Ryde, Jan 01 2024
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Benoit Cloitre, Apr 26 2004
STATUS
approved