login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

a(1) = 1; a(n) = a(n - 1) + n if a(n - 1) < n, a(n) = n^2 if a(n - 1) = n, a(n) = a(n - 1)/n if a(n - 1) > n and a(n - 1) == 0 (mod n), otherwise a(n) = a(n - 1) - n.
2

%I #40 Sep 23 2023 12:11:13

%S 1,3,9,5,25,19,12,4,13,3,14,2,15,1,16,256,239,221,202,182,161,139,116,

%T 92,67,41,14,42,13,43,12,44,11,45,10,46,9,47,8,48,7,49,6,50,5,51,4,52,

%U 3,53,2,54,1,55,3025,2969,2912,2854,2795,2735,2674,2612,2549

%N a(1) = 1; a(n) = a(n - 1) + n if a(n - 1) < n, a(n) = n^2 if a(n - 1) = n, a(n) = a(n - 1)/n if a(n - 1) > n and a(n - 1) == 0 (mod n), otherwise a(n) = a(n - 1) - n.

%H Felix Huber, <a href="/A365203/b365203.txt">Table of n, a(n) for n = 1..10000</a>

%e a(2) = a(1) + 2 = 3, since a(1) = 1 < 2.

%e a(3) = 3^2 = 9, since a(2) = 2.

%e a(4) = a(3) - 4 = 5, since a(3) = 9 > 4 and 9 != 0 (mod 4).

%e a(83) = a(82)/83 = 14, a(82) = 1162 > 83 and 1162 == 0 (mod 83).

%p A365203 := proc(n) option remember;

%p if n = 1 then 1;

%p elif procname(n - 1) < n then procname(n - 1) + n;

%p elif n = procname(n - 1) then n*n;

%p elif irem(procname(n - 1), n) = 0 then procname(n - 1)/n;

%p else procname(n - 1) - n;

%p end if;

%p end proc;

%p seq(A365203(n), n = 1 .. 10000);

%o (PARI) lista(nn) = my(va = vector(nn)); va[1] = 1; for (n=2, nn, my(vs = sign(va[n-1] - n)); if (vs<0, va[n] = va[n-1] + n, if (vs==0, va[n] = n^2, if ((va[n-1] % n)== 0, va[n] = va[n-1]/n, va[n] = va[n-1] - n)));); va; \\ _Michel Marcus_, Aug 27 2023

%o (Python)

%o from itertools import count, islice

%o def A365203_gen(): # generator of terms

%o yield (a:=1)

%o for n in count(2):

%o if a<n:

%o b = a+n

%o elif a==n:

%o b = n**2

%o elif a%n:

%o b = a-n

%o else:

%o b = a//n

%o yield (a:=b)

%o A365203_list = list(islice(A365203_gen(),30)) # _Chai Wah Wu_, Sep 23 2023

%Y Cf. A000290, A046901.

%K easy,nonn

%O 1,2

%A _Felix Huber_, Aug 26 2023