PRMFN - Prime Friendly Numbers
Given N, find the largest number X not greater than N such that X is prime friendly. A number is called prime friendly when it satisfies both of the following conditions:
- The number itself is a prime.
- All its digits in base 10 are also primes. In other words, the number consists of only the digits 2, 3, 5, 7.
The first line contains an integer T, denoting the number of test cases. Each test case contains a single positive integer N.
For each test case, output the case number followed by the largest number X not greater than N. Please refer to the sample input/output section for more clarity of the format.
Input: 5 10 100 1000 10000 100000 Output: Case 1: 7 Case 2: 73 Case 3: 773 Case 4: 7757 Case 5: 77773
Appreciate lenient TL as this was a bit nasty to write. Would probably keep postponing getting it done if I wasn't sure a correct solution passes.