OFFSET
1,2
COMMENTS
Terms computed by Claudio Meller.
LINKS
Michael De Vlieger, Table of n, a(n) for n = 1..10000
Index entries for linear recurrences with constant coefficients, signature (0,1,0,1,0,-1).
FORMULA
a(2*n+1)=3*n; a(4*n+0)=3*n+1; a(4*n+2)=3*n+2. - Kevin Ryde, Feb 11 2022
EXAMPLE
For n = 6; n is even so a(6) = 5 because 5 is the least positive integer not yet in the sequence.
For n = 7; n is odd so a(7) = a(6) + a(4) = 5 + 4 = 9.
MATHEMATICA
a[1] = 1; a[2] = 2; a[3] = 3; a[n_] := a[n] = If[OddQ[n], a[n - 1] + a[n - 3], Module[{k = 4, s = Array[a, n - 1]}, While[! FreeQ[s, k], k++]; k]]; Array[a, 100] (* Amiram Eldar, Feb 10 2022 *)
PROG
(PARI) s=2^0; for (n=1, #a=vector(79), print1 (a[n]=if (n<=3, n, n%2==0, valuation(s+1, 2), a[n-1]+a[n-3])", "); s=bitor(s, 2^a[n])) \\ Rémy Sigrist, Feb 14 2022
(PARI) a(n) = if(n==1, 1, n%2, 3*n>>1 - 1, 3*n>>2 + 1); \\ Kevin Ryde, Feb 21 2022
(Python)
def A351412(n):
if n == 1:
return 1
q, r = divmod(n, 4)
if r == 0:
return n-q+1
elif r == 2:
return n-q
elif r == 1:
return n+2*q-1
else:
return n+2*q # Chai Wah Wu, Feb 19 2022
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Rodolfo Kurchan, Feb 10 2022
STATUS
approved