login
For n>1, if n mod a(n-1) = 0 or a(n-1) mod n = 0, set a(n) = n + a(n-1); otherwise a(n) = abs(n - a(n-1)). Start with a(1)=1.
1

%I #29 May 20 2024 10:29:58

%S 1,3,6,2,3,9,2,10,1,11,22,10,3,11,4,20,3,21,2,22,1,23,46,22,3,23,4,32,

%T 3,33,2,34,1,35,70,34,3,35,4,44,3,45,2,46,1,47,94,46,3,47,4,56,3,57,2,

%U 58,1,59,118,58,3,59,4,68,3,69,2,70,1,71,142,70,3

%N For n>1, if n mod a(n-1) = 0 or a(n-1) mod n = 0, set a(n) = n + a(n-1); otherwise a(n) = abs(n - a(n-1)). Start with a(1)=1.

%C Starting at n=5, the sequence follows a set pattern every 12 terms: a(n) = n-2, 3, n-3, 4, n+4, 3, n+3, 2, n+2, 1, n+1, 2n according as n == 0 to 11 (mod 12), respectively.

%C This means a new peak is reached every 12th term, starting from n = 11.

%H Paolo Xausa, <a href="/A372696/b372696.txt">Table of n, a(n) for n = 1..10000</a>

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

%e For a(2), as a(1) = 1 and n = 2 and 2 mod 1 = 0, use 2+1 = 3.

%e For a(3), as a(2) = 3 and n = 3 and 3 mod 3 = 0, use 3+3 = 6.

%e For a(4), as a(3) = 6 and n = 4 and 6 mod 4 != 0 and 4 mod 6 != 0, use abs(4-6) = 2.

%t Block[{n = 1}, NestList[If[Divisible[++n, #] || Divisible[#, n], n + #, Abs[n - #]] &, 1, 100]] (* _Paolo Xausa_, May 20 2024 *)

%K nonn,easy

%O 1,2

%A _Sameer Khan_, May 10 2024