Prime Digit Number

5

2 votes
Mathematics, Medium, Mathematics, Mathematics, Mathamatics
Problem

You are given a large integer value n. Find the largest number x such that xn and all digits of x are prime.

Input:
Only line of input consists of a single integer denoting n.

Output:
Print the required answer.

Constraints:
1Numberofdigitsinn105
There will be no leading zeroes in n.
n2

Sample Input
1000
Sample Output
777
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

777 is the largest number less than or equal to 1000 having all it's digits prime.

Editor Image

?