Tuesday, September 8, 2009

Sum of Digits

This is just an intriguing fact I discovered while doing a project euler problem (number 56 to be specific). The problem asked for the largest sum of digits of any number of the form a^b where both a and b are between 0 and 100. As I often do, I'm going through a rather circuitous path in discovering the answer. While doing this, I happened upon an interesting fact about numbers. If you subtract the sum of the digits of any number, from the number itself, you gain a multiple of nine. That is



Where S(x) obviously denotes the sum of the digits of x. I honestly don't know why this is true just yet. Though, I do know that a similar formula is true for all other bases. That is, for any number n written in base b, if you subtract the sum of the digits of x from I decided to explore this some more. I wanted to see if I could define a function F(x) that defines the exact multiple of nine that results from subtracting the sum of the digits of a number from the number itself. What I mean to say is I want to find a function such that



So, I did some experimenting. I wrote a program that listed the values f(n) should take on from 1 to 100. It turns out that it followed a rather simple pattern.



Though, this probably won't get me any closer to solving the problem, it is something interesting to think about. Just thought I'd share.