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”).
%I #57 Aug 04 2022 15:45:58
%S -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,
%T -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,
%U 0,0,0,-1,0,0,-1,0,0,0,0,0,0,-1,0,-1,0,0,0,0,0,0
%N 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.
%C sumdigits(x) = A007953(x) is the sum of the decimal digits of x.
%C 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.
%C a(102) = 1 is the first term that is neither 0 nor -1.
%C a(1008) is the first term whose value is 2.
%C a(10080) is the first term whose value is 3.
%C a(100800) is the first term whose value is 4.
%C a(1008000) is the first term whose value is 5.
%D D. R. Kaprekar, Multidigital Numbers, Scripta Mathematica 21 (1955), 27.
%e 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.
%p a:= proc(n) option remember;
%p `if`(irem(n, add(i, i=convert(n, base, 10)), 'm')>0, 0,
%p `if`(n=m, -1, (t-> `if`(t<0, t, t+1))(a(m))))
%p end:
%p seq(a(n), n=1..102); # _Alois P. Heinz_, Apr 08 2022
%o (Python)
%o def sumdigits(n: int) -> int:
%o return sum(map(int, str(n)))
%o def a(n: int) -> int:
%o i = 0
%o while True:
%o denom = sumdigits(n)
%o if denom == 1:
%o i = -1
%o break
%o elif n % denom == 0:
%o i = i + 1
%o n = n // denom
%o else:
%o break
%o return i
%Y Cf. A005349, A007953, A065877, A188641, A235507, A235697.
%K sign,base,easy
%O 1
%A _Jonathan Berliner_, Apr 06 2022