#B4224. Limited Digit Prime
Limited Digit Prime
Limited Digit Prime
A prime number is a natural number greater than \(1\) which has no positive divisors other than \(1\) and itself. In other words, a number \(n\) is prime if and only if its only divisors are \(1\) and \(n\). For example, \(2,3,5,7,11,13,\dots\) are prime numbers, whereas \(4,6,8,9,10,\dots\) are composite numbers. In particular, \(0\) and \(1\) are neither prime nor composite.
Little Y wonders what the smallest prime number is under some restrictions. Normally, the smallest prime is \(2\); however, he now restricts the formation of a prime number to only the use of certain digits. You are given a string that contains the allowed digits. You can use these allowed digits any number of times (repetition is allowed) to form a number. It is not required to use all the given digits. For example:
- If the allowed digit is
3
, then the smallest prime is3
. - If the allowed digit is
1
, then you cannot form1
(since \(1\) is not prime) and the next possibility is11
, which is prime. - If the allowed digits are
8
and9
, then the smallest prime is89
. - If the allowed digits are
3
and5
, then the smallest prime is3
(you are allowed to use a subset of the digits).
Your task is to determine the smallest prime number that can be formed using only the allowed digits.
inputFormat
The input consists of a single line containing a non-empty string of digits. These digits represent the allowed digits from which you can form numbers. You are allowed to use any of the digits any number of times, and you do not need to use all of them. Note that the number you form should not have leading zeros.
outputFormat
Output the smallest prime number (as a string of digits) that can be formed using only the allowed digits.
sample
3
3