To steal a precious jewel, a thief must discover the code that allows him to open the safe's door. The information he managed to obtain is the following:
- the code is a number
- any subsequence of consecutive digits of the code (thus every single digit taken individually, as well as every pair of digits, etc., up to the entire number) represents a prime number (for example, 217 does not work, because 1 is not a prime and 21 is not a prime)
- the code is the largest number having this property.
What is the secret code to open the safe?
Problem 1830
Official solution
Solution:
The answer is .
Let us find all numbers that satisfy the conditions of the problem.
First of all, notice that if we have found all acceptable numbers with digits, then an acceptable number with digits must necessarily contain one of the numbers with digits. In particular, if we discover that no number with digits exists, then no acceptable number with more than digits will exist.
The acceptable numbers with one digit are the one-digit primes, that is and . Notice, however, that the digit and the digit can only appear at the beginning of an acceptable number (otherwise the number would have a subsequence divisible by or by respectively).
The acceptable numbers with two digits are therefore .
Let us now look at the numbers with digits. None can end in or in . Then , , and are not acceptable since they are multiples of . No number can begin with the same pair of digits, otherwise it would have a subsequence that is a multiple of (for example in the subsequence is a multiple of ). What remains to be checked are , which turns out to be prime (and therefore acceptable), and , which is a multiple of .
Let us now see whether there can be numbers with digits. We only need to check of them: , , and . The first and the third contain a subsequence that is a multiple of . The second contains a subsequence that is a multiple of , and the last turns out to be a multiple of . Therefore no acceptable numbers with digits exist and, for the reason stated at the beginning, no acceptable numbers with more than digits will exist either. The sought code is therefore .