# Page Numbering — Puzzle for Interview rounds

# Question :

Pages of a book are numbered sequentially starting with 1. If the total number of decimal digits used is equal to 1578, how many pages are there in the book?

# Solution :

The answer is **562 pages**

Let D(n) be the total number of decimal digits in the first n positive integers (book pages). The first nine numbers are one-digit, therefore D(n) = n for 1 ≤ n ≤ 9.

The next 90 numbers from 10 to 99, inclusive, are two-digits. Hence,

D(n) = 9 + 2(n − 9) for 10 ≤ n ≤ 99.

The maximal value of D(n) for this range is D(99) = 189, which means that some three-digit numbers are needed to reach the total digit count of 1578 given in the puzzle. There are 900 three-digit decimals, which leads to the formula

D(n) = 189 + 3(n − 99) for 100 ≤ n ≤ 999.

To answer the puzzle’s question, we need to solve the equation

189 + 3(n − 99) = 1578.

Its solution is **n = 562**.