OFFSET
1,2
LINKS
Felix Huber, Table of n, a(n) for n = 1..10000
EXAMPLE
a(2) = a(1) + 2 = 3, since a(1) = 1 < 2.
a(3) = 3^2 = 9, since a(2) = 2.
a(4) = a(3) - 4 = 5, since a(3) = 9 > 4 and 9 != 0 (mod 4).
a(83) = a(82)/83 = 14, a(82) = 1162 > 83 and 1162 == 0 (mod 83).
MAPLE
PROG
(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
(Python)
from itertools import count, islice
def A365203_gen(): # generator of terms
yield (a:=1)
for n in count(2):
if a<n:
b = a+n
elif a==n:
b = n**2
elif a%n:
b = a-n
else:
b = a//n
yield (a:=b)
CROSSREFS
KEYWORD
easy,nonn
AUTHOR
Felix Huber, Aug 26 2023
STATUS
approved