login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A352871
a(n) is the number of iterations, starting with x = n, which can be made of x -> x/sumdigits(x) with x remaining an integer, or -1 if x remains an integer through infinitely many iterations.
0
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, 0, 0, 0, 0, -1, 0, -1, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, -1, 0, -1, 0, 0, -1, 0, 0, -1, 0, -1, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, 0, 0, 0, 0, 0
OFFSET
1
COMMENTS
sumdigits(x) = A007953(x) is the sum of the decimal digits of x.
A Harshad number (A005349) is divisible by the sum of its digits and the iterations here step through Harshad numbers until reaching a non-Harshad number.
a(102) = 1 is the first term that is neither 0 nor -1.
a(1008) is the first term whose value is 2.
a(10080) is the first term whose value is 3.
a(100800) is the first term whose value is 4.
a(1008000) is the first term whose value is 5.
REFERENCES
D. R. Kaprekar, Multidigital Numbers, Scripta Mathematica 21 (1955), 27.
EXAMPLE
13000/(1+3+0+0+0) = 3250, and 3250/(3+2+5+0) = 325, but 325/(3+2+5) is not an integer, so a(13000) = 2.
MAPLE
a:= proc(n) option remember;
`if`(irem(n, add(i, i=convert(n, base, 10)), 'm')>0, 0,
`if`(n=m, -1, (t-> `if`(t<0, t, t+1))(a(m))))
end:
seq(a(n), n=1..102); # Alois P. Heinz, Apr 08 2022
PROG
(Python)
def sumdigits(n: int) -> int:
return sum(map(int, str(n)))
def a(n: int) -> int:
i = 0
while True:
denom = sumdigits(n)
if denom == 1:
i = -1
break
elif n % denom == 0:
i = i + 1
n = n // denom
else:
break
return i
CROSSREFS
KEYWORD
sign,base,easy
AUTHOR
Jonathan Berliner, Apr 06 2022
STATUS
approved