login
A351412
a(1) = 1, a(2) = 2, a(3) = 3. Then if n is even a(n) is the least positive integer not yet in the sequence, otherwise if n is odd a(n) = a(n-1) + a(n-3).
1
1, 2, 3, 4, 6, 5, 9, 7, 12, 8, 15, 10, 18, 11, 21, 13, 24, 14, 27, 16, 30, 17, 33, 19, 36, 20, 39, 22, 42, 23, 45, 25, 48, 26, 51, 28, 54, 29, 57, 31, 60, 32, 63, 34, 66, 35, 69, 37, 72, 38, 75, 40, 78, 41, 81, 43, 84, 44, 87, 46, 90, 47, 93, 49, 96, 50, 99, 52, 102, 53, 105, 55, 108, 56, 111, 58, 114, 59, 117
OFFSET
1,2
COMMENTS
Terms computed by Claudio Meller.
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
Sequence in context: A276685 A225040 A327173 * A118315 A280577 A075159
KEYWORD
nonn,easy
AUTHOR
Rodolfo Kurchan, Feb 10 2022
STATUS
approved