OFFSET
1,2
COMMENTS
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.)
EXAMPLE
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):
row k numbers T(k,j) = k(k-1)/2 + j, j = 1..k
----- ---------------------------------------
1 1;
2 2, 3;
3 4, 5, 6;
4 7, 8, 9, 10;
5 11, 12, 13, 14, 15;
etc.
After a(1) = 1, a(2) is the 1st term of the 2nd row of the triangle, a(2) = 2.
Then a(3) is the a(2)-th = 2nd term of the 3rd row, a(3) = 5.
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.
Similarly, a(5) = 8 is the a(4)-th = 7th term of the 5th row, with cyclic indexing (so actually the 2nd term).
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.
MAPLE
a:= proc(n) option remember; `if`(n<2, n,
n*(n-1)/2 + ((a(n-1)-1) mod n) + 1)
end:
seq(a(n), n=1..60); # Alois P. Heinz, Apr 23 2020
MATHEMATICA
a[n_] := a[n] = If[n<2, n, n(n-1)/2 + Mod[a[n-1]-1, n] + 1];
Array[a, 60] (* Jean-François Alcover, Nov 30 2020, after Alois P. Heinz *)
PROG
(PARI) for(n=2, #a=Vec(1, 100), a[n]=n*(n-1)/2 + (a[n-1]-1)%n + 1); a
CROSSREFS
KEYWORD
nonn
AUTHOR
Ali Sada and M. F. Hasler, Mar 06 2020
STATUS
approved