[Q&A] How Many Digits Are There?

[Problem Solution] How Many Digits Are There?

Having solved the previous problem, "How Many 5's Are There?", Zirui mentioned seeing a similar problem — one that, admittedly, is a bit harder:

A number is such that its digits sum to 900, and when the number is doubled, the digits of the result still sum to 900. Given that this number is composed only of the digits 3, 4, 5, and 6, how many digits does the product of the largest and smallest numbers satisfying this condition have?

To answer this, we just need to know how many digits the largest number and the smallest number each have. The largest number must be of the form 6...3, while the smallest number can only be of the form 3...6, and the total number of digits we're after is the sum of their respective digit counts.

How do we compare the sizes of two numbers? Clearly, when the numbers of digits differ, the one with more digits is larger; when the numbers of digits are the same, we compare digit by digit from the most significant to the least. So what we need to work out is the maximum and minimum possible number of digits.

Let the number contain a 3's, b 4's, c 5's, and d 6's. From the given conditions:

$$3a+4b+5c+6d=900\tag{1}$$$$6a+8b+c+3d=900\tag{2}$$

Denote $s=a+b+c+d$, where s is the total digit count. We want the maximum and minimum values of s. Here, since we have two equations, only two of the variables a, b, c, d are independent; moreover, due to the constraints of the problem itself, they must all be positive integers. So this is essentially a simple linear programming and number theory problem.

From $(1) \times 2-(2)$ we get:

$$c+d=100$$

This shows that c and d are not independent, and consequently a and b are not independent either.

From $(1)+(2)$ we get:

$$3a+4b+2c+3d=600$$

that is, $s=200+\frac{c-b}{3}$

The above reasoning shows that c and b are independent. So to find the maximum s, let's try b=1, c=97 as a trial; substituting in, we find that a=131 is indeed a valid solution. That gives us the answer: the maximum s is 232.

Similarly, to find the minimum s, let's try c=1, which gives d=99. Substituting into $3a+4b+2c+3d=600$ gives

$$3a+4b=301$$

Taking the largest possible b, when a=3 we get b=73; substituting this into $s=200+\frac{c-b}{3}$ gives exactly the integer s=176.

We have good reason to believe that the minimum s is indeed 176. Of course, if you're still not convinced, you could try c=2 as well and see what result you get. There's no need to go on trying c=3, 4, and so on, because in general, as c increases, b decreases, which means c−b actually grows larger.

So we arrive at the final answer: 232+176=408 — the total number of digits asked for in the original problem!

English translation of a post from 科学空间 | Scientific Spaces by 苏剑林. Original: https://kexue.fm/archives/1922
Translated automatically with claude-sonnet-5; all equations are reproduced verbatim from the source. Copyright remains with the original author.