OFFSET
1,2
COMMENTS
1, 2 and the third column of A357554.
LINKS
Robert Israel, Table of n, a(n) for n = 1..10000
FORMULA
a(n) = 3 if n is divisible by 3.
a(3*k+1) = k+1.
a(15*k+5) = 5 for k >= 1.
a(15*k+11) = 3*k+3.
a(255*k+137) = 15*k+9 for k >= 1.
EXAMPLE
a(4) = 2 because we have 3 -> floor(4/3) + (4 mod 3) = 2 -> floor(4/2) + (4 mod 2) = 2.
MAPLE
g:= proc(n, k) local x, S;
S:= {k};
x:= k;
do
x:= iquo(n, x) + irem(n, x);
if member(x, S) then return x fi;
S:= S union {x};
od
end proc:
seq(g(n, 3), n=1..100);
MATHEMATICA
T[n_, k_] := Module[{x, S}, S = {k}; x = k; While[True, x = Total@QuotientRemainder[n, x]; If[MemberQ[S, x], Return[x]]; S = S~Union~{x}]];
a[n_] := T[n, 3];
Table[a[n], {n, 1, 100}] (* Jean-François Alcover, Oct 17 2022, after Maple code *)
PROG
(Python)
def a(n):
seen, x = set(), 3
while x not in seen: seen.add(x); q, r = divmod(n, x); x = q + r
return x
print([a(n) for n in range(1, 90)]) # Michael S. Branicky, Oct 06 2022~
CROSSREFS
KEYWORD
nonn,look
AUTHOR
J. M. Bergot and Robert Israel, Oct 06 2022
STATUS
approved