%I #13 Sep 15 2018 02:04:27
%S 2,4,9,8,8,25,12,12,29,16,16,37,20,20,61,24,24,57,28,28,65,32,32,129,
%T 36,36,85,40,40,93,44,44,129,48,48,113,52,52,121,56,56,165,60,60,141,
%U 64,64,149,68,68,265,72,72,169,76,76,177,80,80,233,84,84,197,88,88,205
%N Define r(k) as follows: r(1)=n, r(k+1) = r(k) +(-1)^k*sign(r(k)-k)*k; then abs(r(k)) = n for at least one k>1 (there could be 2 values for k > 1). Sequence gives the smallest value of k > 1 such that abs(r(k)) = n.
%C If n=3k+1 or 3k+2, abs(r(x))=n for x=4k+4 and x=8k+1 (first solution only is in the sequence). This was inspired by Recamán's sequence (A005132).
%F For k >= 1, a(3k+1) = a(3k+2) = 4k+4;
%F for m >= 2, k >= 1, a(3^m*k) = 3^(m-2)*28*k+1.
%F For a(3^m*k+a) it is more complicated to give a general formula, as examples: a(9k+3) = 28k+9; a(9k+6) = 36k+25; a(27k+3) = 84k+9; a(27k+6) = 104k+25; a(27k+9) = 84k+29; a(27k+12) = 84k+37; a(27k+24) = 136k+129.
%F Sum_{k=1..n} a(k) is asymptotic to n^2.
%e If r(1)=5: r(8)=5, hence a(5)=8.
%Y Cf. A005132.
%K nonn
%O 1,1
%A _Benoit Cloitre_, Oct 31 2002