how can you count number of digits used in numbers from -2^127 to (2^(127) - 1)

262 Views Asked by At

There are numbers from -2^127 to (2^127)-1.
I want to count the number of digits used in all the numbers.

For example
If I have numbers from -100 to 100 then number of digits used is $2*(1*9 + 2*90 + 3*1) + 1$ (including 0 only once)
9 numbers having 1 digit.
90 numbers having 2 digits.
1 number having 3 digits.
but same for all -100 to 0 numbers therefore double the answer
and we forgot the 0 so $+ 1$.

1

There are 1 best solutions below

6
On BEST ANSWER

[There are 90 two-digit positive integers, not 89.]

Note that $38<\log_{10}(2^{127}-1)<39$, so $2^{127}$ has 39 digits. Then the number of digits in numbers from $1$ to $2^{127}-1$ is $$d=1\cdot9+2\cdot90+3\cdot900+\cdots+38\cdot9\cdot{10}^{37}+39\cdot(2^{127}-10^{38}),$$ and the number of digits used in the numbers from $-2^{127}$ to $2^{127}-1$ is therefore $2d+2=13048790087694377852849387467616738024564$.

If each digit weighs one microgram, this is several times the mass of the sun.