OFFSET
1,2
EXAMPLE
a(6) = 3, as a(3) = 6 = n, thus a(6) = 3.
a(28) = 1316 because subtracting 28 from the previous term (47) would give 19, which is already in the sequence, so multiply 47 by 28 to get 1316.
a(100) = 25, as a(25) = 100 = n, thus a(100) = 25.
MATHEMATICA
a[1] = 1; a[n_] := a[n] = Module[{s = Array[a, n - 1], a1}, If[MemberQ[s, n], Position[s, n][[-1, 1]], a1 = a[n - 1] - n; If[a1 < 0 || MemberQ[s, a1], a[n - 1]*n, a1]]]; Array[a, 100] (* Amiram Eldar, Jul 23 2023 *)
PROG
(MATLAB)
function a = A363962( max_n )
a = 1;
for n = 2:max_n
r = find(a == n, 1, 'last');
if ~isempty(r)
a(n) = r;
else
k = a(n-1) - n;
if k > 0 && isempty(find(a == k, 1))
a(n) = k;
else
a(n) = a(n-1) * n;
end
end
end
end % Thomas Scheuerle, Jul 03 2023
CROSSREFS
KEYWORD
nonn
AUTHOR
Kelvin Voskuijl, Jun 29 2023
STATUS
approved