OFFSET
0,3
COMMENTS
The sequence includes every ordered pair of positive integers exactly once as consecutive terms of the sequence. Through n = k^2, it has every pair i,j with 0 < i,j <= k.
Can be regarded as an irregular triangle where row k contains 1, k, k, k-1, k, k-2, ..., 2, k, with 2n-1 terms.
See A305615 for an essentially identical sequence: a(n) = A305615(n)+1. - N. J. A. Sloane, Jul 03 2018
FORMULA
Let r = ceiling(sqrt(n)) = A003059(n). If n and r have the same parity, a(n) = (r^2-n)/2 + 1; otherwise a(n) = r.
EXAMPLE
The first 3 occurs as a(5), so a(6) = 3, the first term of 3, 2, 1, 4, 5, 6, .... The second 3 is thus a(6), so a(7) = 2. The third 3 is a(8), so a(9) = 1. The fourth 3 is a(12), now we start incrementing, and a(13) = 4.
The triangle starts:
1
1, 2, 2
1, 3, 3, 2, 3
1, 4, 4, 3, 4, 2, 4
1, 5, 5, 4, 5, 3, 5, 2, 5
PROG
(PARI) a(n) = my(r = if(n<=0, 0, sqrtint(n-1)+1)); if((n-r)%2, r, (r^2-n)/2 + 1)
CROSSREFS
KEYWORD
nonn,tabf,changed
AUTHOR
Franklin T. Adams-Watters, Mar 04 2016
STATUS
approved