Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #23 Dec 27 2022 18:47:13
%S 0,0,1,2,3,4,5,6,7,8,-1,0,1,2,3,4,5,6,7,8,0,1,2,3,4,5,6,7,8,9,1,2,3,4,
%T 5,6,7,8,9,10,2,3,4,5,6,7,8,9,10,11,3,4,5,6,7,8,9,10,11,12,4,5,6,7,8,
%U 9,10,11,12,13,5,6,7,8,9,10,11,12,13,14,6,7,8,9,10,11,12,13,14,15,7
%N Sum of digits of n minus the number of digits of n.
%C Concerning 0 we use the convention that 0 has 0 digits, so a(0) = 0 - 0 = 0, a(1) = 1 - 1 = 0, and a(10) = 1 - 2 = -1 is the first negative terms of the sequence.
%H Harvey P. Dale, <a href="/A321999/b321999.txt">Table of n, a(n) for n = 0..1000</a>
%F a(n) = A007953(n) - A004218(n+1) = A007953(n) - A055642(n) for all n > 0. a(m*10^k) = a(m) - k for all m > 0, k >= 0, in particular:
%F a(10^k) = -k for all k >= 0. a(m) = m - 1 for 0 < m < 10.
%F a(n+1) = a(n) + 1 unless n = 9 (mod 10), in which case a(n+1) = a((n+1)/10).
%F a(10^k-1) = 8*k.
%e a(0) = 0 - 0 = 0. (We consider 0 has 0 digits.)
%e a(1) = 1 - 1 = 0;
%e a(2) = 2 - 1 = 1, ...,
%e a(9) = 9 - 1 = 8. (General formula: a(10^k - 1) = 8*k.)
%e a(10) = 1 - 2 = -1. (General formula: a(10^k) = -k.)
%e a(11) = 1+1 - 2 = 0, ...,
%e a(19) = 1+9 - 2 = 8;
%e a(20) = 2+0 - 2 = 0. (General formula: a(m*10^k) = a(m) - k.)
%e a(29) = 2+9 - 2 = 9, ...,
%e a(99) = 9+9 - 2 = 16: cf. a(9);
%e a(100) = 1+0+0 - 3 = -2;
%e a(101) = 1+0+1 - 3 = -1;
%e a(102) = 1+0+2 - 3 = 0, ...,
%e a(109) = 1+0+9 - 3 = 7;
%e a(110) = 1+1+0 - 3 = -1, ...,
%e a(119) = 1+1+9 - 3 = 8, ...,
%e a(199) = 1+9+9 - 3 = 16,
%e a(200) = 2+0+0 - 3 = -1: cf. a(20), ...,
%e a(999) = 9+9+9 - 3 = 24: cf. a(9);
%e a(1000) = 1+0+0+0 - 4 = -3, ...,
%e a(1001) = 1+0+0+1 - 4 = -2, ....
%p a:= n-> add(i, i=convert(n, base, 10))-length(n):
%p seq(a(n), n=0..100); # _Alois P. Heinz_, Dec 10 2018
%t Table[(Plus@@IntegerDigits[n]) - Length[IntegerDigits[n]] + KroneckerDelta[n, 0], {n, 0, 99}] (* _Alonso del Arte_, Dec 07 2018 *)
%t Table[Total[IntegerDigits[n]]-IntegerLength[n],{n,0,100}] (* _Harvey P. Dale_, Dec 27 2022 *)
%o (PARI) A321999(n)=sumdigits(n)-if(n,logint(n,10)+1)
%Y Cf. A007953 (digit sum of n), A004218 (ceiling(log_10(n))), A055642 (number of digits of n).
%Y The zeroes of this sequence, except 0 itself, are in A061384.
%K base,sign
%O 0,4
%A _M. F. Hasler_, Dec 07 2018