P2821 Transform Number

Description

Given a positive decimal integer $n$, its recursive "transform number" is defined as follows: - If $n$ has more than 1 digit (ignoring leading zeros), multiply all its digits, and let the product be $m$. Call $m$ a "sub-transform number" of $n$, and call $n$ a "parent transform number" of $m$. To compute the "transform number" of a number means to keep taking its sub-transform number recursively. That is, computing the transform number of $n$ is the same as computing the transform number of $m$. - If $n$ has exactly one digit, then its transform number is itself. For example, the process for the transform number of $679$ is: $679 \to 378(6 \times 7 \times 9) \to 168(3 \times 7 \times 8) \to 48(1 \times 6 \times 8) \to 32(4 \times 8) \to 6(2 \times 3)$, so the transform number of $679$ is $6$. Now, given a sub-transform number $k$, what is the smallest parent transform number of $k$? For example, when $k=18$, the parent transform number can be $29$ or $92$, but the smallest is $29$.

Input Format

A sub-transform number $k$ (number of digits $\le 1000$).

Output Format

The smallest parent transform number of $k$. If no parent transform number exists, output `There is no such number!`.

Explanation/Hint

Translated by ChatGPT 5