My Math Forum

My Math Forum (
-   Number Theory (
-   -   Sum of number's number (

Vitty June 28th, 2019 12:53 PM

Sum of number's number
Hey, I have a number theory problem: determine the sum of the digits of a natural number. I have been thinking about it for a lot time during this days, but I can't still find a solution. Can someone give me an idea or advise me a book/internet site with something useful?

Thank a lot.

mathman June 28th, 2019 01:48 PM

Add them up? What are you looking for?

DarnItJimImAnEngineer June 28th, 2019 03:33 PM

I can find it modulo 9 no problem. :p

Greens June 28th, 2019 05:52 PM

This seems pretty brute force, wouldn't surprise me at all if there was something more elegant.

Let each digit $d_i \in \{0,1,2 \dots , 9\}$ be such that

$\displaystyle d_{1}d_{2}d_{3} \dots d_{N} = a \in \mathbb{N}$

(This is concatenation, but also $\displaystyle a= \sum_{i=1}^{N} d_{i}10^{(N-i)}$ )

Then we know $d_1 = floor \left(10^{-(N-1)}a \right)$

Now, we know $a-10^{(N-1)}d_{1} = d_{2}d_{3} \dots d_{N}$

thus $d_{2} = floor \left(10^{-(N-2)} \left(a-10^{(N-1)}d_{1} \right) \right)$

and $d_{3} = floor \left(10^{-(N-3)} \left(a-10^{(N-1)}d_{1} - 10^{(N-2)}d_{2} \right) \right)$

Continuing this strategy leaves

$\displaystyle d_{n} = floor \left( 10^{-(N-n)} \left( a - \sum_{i=1}^{n-1} d_{i}10^{(N-i)} \right) \right) $

So, the sum of digits should be

$\displaystyle \sum_{i=1}^{N}d_{i} = floor \left(10^{-(N-1)}a \right) + \sum_{n=2}^{N} floor \left( 10^{-(N-n)} \left( a - \sum_{i=1}^{n-1} d_{i}10^{(N-i)} \right) \right)$

For $N \geq 2$

Vitty June 28th, 2019 11:34 PM

Thanks for your answer. I tried with another different way:

-Let $\displaystyle d_i \in \{0,1,2 \dots , 9\}$ and $\displaystyle \displaystyle d_{1}d_{2}d_{3} \dots d_{N} = a \in \mathbb{N}$

-Now I know that each digit is generated by: $\displaystyle d_i = \sum_{i=1}^{\left \lfloor log_{10}(A)+1 \right \rfloor}\frac{A\,\, mod\,\, 10^{i}-A\,\, mod\,\, 10^{i-1}}{10^{i-1}}$

-I expand the sum and I obtain: $\displaystyle \frac{A\, mod\,\, 10-A\,\, mod\,\, 1}{1}+\frac{A\, mod\,\, 10^{2}-A\,\, mod\,\, 10}{10}+\cdots +\frac{A\, mod\,\, 10^{i}-A\,\, mod\,\, 10^{i-1}}{10^{i-1}}$

-I have to simplify the denominator so: $\displaystyle \frac{1\cdot (A\, mod\,\, 10-A\,\, mod\,\, 1)}{1}+\frac{10\cdot (\frac{A}{10}\, mod\,\, 10-\frac{A}{10}\,\, mod\,\, 1)}{10}+\cdots +\frac{10^{i-1}\cdot (\frac{A}{10^{i-1}}\, mod\,\, 10-\frac{A}{10^{i-1}}\,\, mod\,\, 1)}{10^{i-1}}$

-I split the term: $\displaystyle A\, \, mod\, \, 10+\frac{A}{10}\, \, mod\, \, 10+\cdots+\frac{A}{10^{i-1}}\, \, mod\, \, 10-(A\, \, mod\, \, 1+\frac{A}{10}\, \, mod\; 1+\cdots +\frac{A}{10^{i-1}}\, \, mod\, \, 1)$

-Now I would have picked up $\displaystyle mod\,\,10$ and $\displaystyle mod\,\,1$: $\displaystyle \left (\sum_{i=1}^{\left \lfloor log_{10}(A)+1 \right \rfloor}\frac{A}{10^{i-1}}\right)\, \, mod\, \, 10-\left (\sum_{i=1}^{\left \lfloor log_{10}(A)+1 \right \rfloor}\frac{A}{10^{i-1}}\right)\, \, mod\, \, 1$; but I can't; some ideas to move forward?


Originally Posted by Greens (Post 611193)
$\displaystyle \sum_{i=1}^{N}d_{i} = floor \left(10^{-(N-1)}a \right) + \sum_{n=2}^{N} floor \left( 10^{-(N-n)} \left( a - \sum_{i=1}^{n-1} d_{i}10^{(N-i)} \right) \right)$

Can we move from this sum to a function without $\displaystyle \sum$?

All times are GMT -8. The time now is 07:49 AM.

Copyright © 2019 My Math Forum. All rights reserved.