A053836 Sum of digits of n written in base 16.
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 5, 6, 7
Offset: 0
Examples
a(20) = 1 + 4 = 5 because 20 is written as "14" in base 16.
Links
- Reinhard Zumkeller, Table of n, a(n) for n = 0..10000
- Robert Walker, Self Similar Sloth Canon Number Sequences
- Eric Weisstein's World of Mathematics, Hexadecimal
- Eric Weisstein's World of Mathematics, Digit Sum
Programs
-
Haskell
a053836 n = q 0 $ divMod n 16 where q r (0, d) = r + d q r (m, d) = q (r + d) $ divMod m 16 -- Reinhard Zumkeller, May 15 2011
-
Mathematica
Table[Plus @@ IntegerDigits[n, 16], {n, 0, 150}] (* Vladimir Joseph Stephan Orlovsky, Jul 19 2011 *)
-
PARI
a(n)=if(n<1,0,if(n%16,a(n-1)+1,a(n/16)))
-
PARI
a(n) = sumdigits(n, 16); \\ Michel Marcus, Jan 19 2023
-
Python
def A053836(n): return sum(int(d,16) for d in hex(n)[2:]) # Chai Wah Wu, Jan 19 2023
Formula
a(0)=0, a(16*n+i)=a(n)+i 0<=i<=15; a(n)=n-15*Sum_{k>0} floor(n/16^k). - Benoit Cloitre, Dec 19 2002
Comments