login
a(1) = 1; for n > 1, a(n) = n*(n-1)/2 + ((a(n-1)-1) mod n) + 1, the a(n-1)-th term of the n-th row of the triangle of positive integers, indexed in cyclic manner.
0

%I #23 Nov 30 2020 14:50:16

%S 1,2,5,7,12,21,28,32,41,46,57,75,88,95,110,134,151,160,179,209,230,

%T 241,264,300,325,338,365,379,408,453,484,500,533,584,619,637,674,731,

%U 770,790,831,894,937,959,1004,1073,1120,1144,1193,1268,1319,1345,1398

%N a(1) = 1; for n > 1, a(n) = n*(n-1)/2 + ((a(n-1)-1) mod n) + 1, the a(n-1)-th term of the n-th row of the triangle of positive integers, indexed in cyclic manner.

%C Write the positive integers A000027 in a triangle T(k,j) = k(k-1)/2 + j, k >= j >= 1. Then a(n) is the a(n-1)-th element of the n-th row, with indices taken in [1..n] modulo n. (If a row has fewer than a(n-1) elements, this is equivalent to repeating the elements in a cyclic/periodic manner up to the required length.)

%e Consider the positive integers written in a triangle, the n-th row going from n(n-1)/2 + 1 to n(n+1)/2 = A000217(n):

%e row k numbers T(k,j) = k(k-1)/2 + j, j = 1..k

%e ----- ---------------------------------------

%e 1 1;

%e 2 2, 3;

%e 3 4, 5, 6;

%e 4 7, 8, 9, 10;

%e 5 11, 12, 13, 14, 15;

%e etc.

%e After a(1) = 1, a(2) is the 1st term of the 2nd row of the triangle, a(2) = 2.

%e Then a(3) is the a(2)-th = 2nd term of the 3rd row, a(3) = 5.

%e Then a(4) is the a(3)-th = 5th term of row 4, with cyclic indexing: since the row has only 4 elements, we wrap around in a cyclic manner and come back to the 1st term, a(4) = 7.

%e Similarly, a(5) = 8 is the a(4)-th = 7th term of the 5th row, with cyclic indexing (so actually the 2nd term).

%e a(9) is the 32nd term of row 9 = 37..45 of length 9, i.e., taking modulo 9, the 5th term, 36+5 = 41.

%p a:= proc(n) option remember; `if`(n<2, n,

%p n*(n-1)/2 + ((a(n-1)-1) mod n) + 1)

%p end:

%p seq(a(n), n=1..60); # _Alois P. Heinz_, Apr 23 2020

%t a[n_] := a[n] = If[n<2, n, n(n-1)/2 + Mod[a[n-1]-1, n] + 1];

%t Array[a, 60] (* _Jean-François Alcover_, Nov 30 2020, after _Alois P. Heinz_ *)

%o (PARI) for(n=2,#a=Vec(1,100), a[n]=n*(n-1)/2 + (a[n-1]-1)%n + 1); a

%Y Cf. A000217, A000027.

%K nonn

%O 1,2

%A _Ali Sada_ and _M. F. Hasler_, Mar 06 2020