Number of digits in 1…n Let n be a positve integer. Consider the task of printing all the numbers f

shmilybaby4i

shmilybaby4i

Answered question

2022-06-24

Number of digits in 1…n
Let n be a positve integer. Consider the task of printing all the numbers from 1 to n. For example, 512 has three digits.
When n is small,the task can be completed quickly; when n is large it can take a long time.
How many digits does it take to print these numbers?

Answer & Explanation

Carmelo Payne

Carmelo Payne

Beginner2022-06-25Added 25 answers

Step 1
A whole sequence of k digits numbers (from 10 k 1 to 10 k 1) totals 9 k 10 k 1 digits. If n has m digits, the last incomplete sequence totals m ( n 10 m 1 + 1 ) digits.
Step 2
Hence, k = 1 m 1 9 k 10 k 1 + m ( n 10 m 1 + 1 ) = m ( n + 1 ) 10 m 1 9
with m := log 10 n + 1.

Do you have a similar question?

Recalculate according to your conditions!

New Questions in Discrete math

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?