Natural numbers verifying $P(n) = n^2 - 42n + 440$, where $P(n)$ is the product of the digits 
Let $P(n)$ be the product of the digits of the number $n$, with $n \in  \mathbb{N}$.
What is the product of all the natural numbers $n$ that verify the equation $P(n) = n^2 - 42n + 440$?

I factorized the polynomial to get $P(n) = (n - 20)(n - 22)$. Then I observed that $n = 20$ is a solution because $P(20) = 0$.
But at this point I got stuck, so I wrote an Haskell program that would calculate the solutions for me. After letting it run for a while I checked the output, which was: $[18, 20, 24]$. So apparently the answer is $18 \cdot 20 \cdot 24 = 8640$.
What is the correct, mathematical way to solve this?
 A: Elaborating on the comments given by fixedp:
The number of digits in $n\in\mathbb N$ equals $\lfloor\log n\rfloor+1$. This is true since $n=10^{\log n}$ so the greatest power of $10$ that is less than or equal to $n$ is $10^{\lfloor\log n\rfloor}$ which has $\lfloor\log n\rfloor+1$ digits, and so does $n$. Since each digit of $n$ is at most $9$, it follows that
$$
P(n)\leq 9^{\lfloor\log n\rfloor+1}<10^{\log n+1}=10n
$$
since this bound is a linear expression in $n$ and $(n-20)(n-22)$ is a quadratic expression we see that $P(n)<10n<(n-20)(n-22)$ for $n$ large enough. Solving the equality $10x=(x-20)(x-22)$ yields $x\approx10.64$ or $x\approx41.36$ so the only range to check is $n\in\{11,12,...,41\}$. In particular only two-digit numbers apply!

Assuming $n=10a+b$ we must solve $ab=(10a+b-20)(10a+b-22)$ which is an elliptic curve with the following integer solutions: Link to Wolfram Alpha Computation.
This shows positively and definitively that the numers $18,20,24$ are in fact the only solutions.

Actually we can reduce the number of numbers to check once again, since we now know that $n\leq 41$ so $P(n)\leq P(39)=3\cdot 9=27$. Solving $27=(x-20)(x-22)$ yields $x\approx 15.71$ or $x\approx 26.29$. So now we only need to check the the range $n\in\{16,17,...,26\}$. It could hardly be easier now ...

If you cannot stop yourself, you can apply the same method to have $P(n)\leq P(26)=2\cdot 6=12$ and solve $12=(x-20)(x-22)$ to get $x\approx 17.39$ or $x\approx 24.6$ and therefore $n\in\{18,19,...,24\}$. Voila!
A: Let $n = \sum_{i=0}^{k-1} d_i \cdot 10^i$  be a number with $k$ digits and $d_i \in \{0,...,9\}$. Then
$$P(n) := \prod_{i=0}^{k-1} d_i$$
So the question is what the solutions are for the equation
\begin{align}
P(n) &= n^2 - 42n + 440\\
\Leftrightarrow \prod_{i=0}^{k-1} d_i &= \left ((\sum_{i=0}^{k-1} d_i \cdot 10^i)-20 \right ) \cdot \left ((\sum_{i=0}^{k-1} d_i \cdot 10^i)-22 \right)\\
\end{align}
Restrictions for solutions


*

*We know that every solution is a natural number (hence > 0).

*As every digit is at most $9$, the left hand side of the equation is at most $9^k = 9^{\lfloor \log n \rfloor + 1} = 9 \cdot 9^{\lfloor \log n \rfloor} < 9 \cdot 9^{\log n} = 9 \cdot n^{\log{9}} < 9 \cdot n$.

*It is easy to show that $\exists n_0 \in \mathbb{N}: \forall n > n_0: n^2- 42n+440 > 9 n$ is true:


\begin{align}
n^2- 42n+440 &\geq 9n\\
\Leftrightarrow n^2- 51n+440 &\geq 0\\
\Leftrightarrow (n-11) \cdot (n-40) &\geq 0
\end{align}


*

*So for $n > n_0 = 40$ we know that there cannot be a solution.


Check candidates
Use the following Python script to check the remaining 40 candidates:
#!/usr/bin/env python


def P(n):
    prod = 1
    for digit in str(n):
        prod *= int(digit)
    return prod


def check(n):
    return P(n) == n**2 - 42*n + 440


if __name__ == '__main__':
    for i in range(41):
        if check(i):
            print(i)

Answers


*

*18

*20

*24

