login
A389235
Number of repeating Harshad algorithm steps until a non-Harshad number or a power of 10 is reached.
4
0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 1, 2, 0, 0, 2, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 2, 0, 0, 2, 0, 0, 2, 0, 1, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0
OFFSET
1,12
COMMENTS
a(n) is the number of Harshad algorithm steps that can be done starting with n and always reaching another Harshad number (See also A114440). Stopping points are non-Harshad numbers or Harshad numbers that are a powers of 10 (See example).
LINKS
Brady Haran and Tony Padilla, The Joy of Harshad Numbers, YouTube video, 2025.
Eric Weisstein, Harshad Numbers.
Wikipedia, Harshad number.
EXAMPLE
a(20) = 1 because digit sum of 20 is 2 and 20/2 = 10.
10 is in fact a Harshad number too, but a Harshad number with an infinite cycle.
So we have to stop here. This happens for all powers of 10.
So a(1), a(10), a(100) ... are always 0.
MATHEMATICA
a[n_] := -1 + Length[NestWhileList[# / DigitSum[#] &, n, DigitSum[#] > 1 && Divisible[#, DigitSum[#]] &]]; Array[a, 100] (* Amiram Eldar, Sep 27 2025 *)
PROG
(Python)
def A389235(n):
c = 0
while not n % (digsum:=sum([int(d) for d in str(n)])) and digsum != 1: n, c = n // digsum, c + 1
return c
print([A389235(n) for n in range(1, 100)])
(PARI) a(n) = {my(k=0, r=n, s); while((s=sumdigits(r)) != 1 && r%s==0, r/=s; k++); k} \\ Andrew Howroyd, Sep 26 2025
KEYWORD
nonn,base,easy,changed
AUTHOR
Karl-Heinz Hofmann, Sep 26 2025
STATUS
approved