login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

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

%I #29 Feb 21 2022 23:35:01

%S 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,

%T 39,22,42,23,45,25,48,26,51,28,54,29,57,31,60,32,63,34,66,35,69,37,72,

%U 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

%N 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).

%C Terms computed by _Claudio Meller_.

%H Michael De Vlieger, <a href="/A351412/b351412.txt">Table of n, a(n) for n = 1..10000</a>

%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>

%H <a href="/index/Rec#order_06">Index entries for linear recurrences with constant coefficients</a>, signature (0,1,0,1,0,-1).

%F 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

%e For n = 6; n is even so a(6) = 5 because 5 is the least positive integer not yet in the sequence.

%e For n = 7; n is odd so a(7) = a(6) + a(4) = 5 + 4 = 9.

%t 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 *)

%o (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

%o (PARI) a(n) = if(n==1,1, n%2, 3*n>>1 - 1, 3*n>>2 + 1); \\ _Kevin Ryde_, Feb 21 2022

%o (Python)

%o def A351412(n):

%o if n == 1:

%o return 1

%o q, r = divmod(n, 4)

%o if r == 0:

%o return n-q+1

%o elif r == 2:

%o return n-q

%o elif r == 1:

%o return n+2*q-1

%o else:

%o return n+2*q # _Chai Wah Wu_, Feb 19 2022

%Y Cf. A006368, A167151.

%K nonn,easy

%O 1,2

%A _Rodolfo Kurchan_, Feb 10 2022