Jadoo and Spiritual Enlightenment
Practice
5 (2 votes)
Maths
Primes
Medium
Problem
11% Success 71 Attempts 30 Points 5s Time Limit 256MB Memory 1024 KB Max Code

Problem Setter: Sagnik Chaudhuri

In order to achieve spiritual enlightenment and get free from the daily chores of his mundane life, Jadoo consulted a Saint who lived high atop a mountain. The Saint was willing to show the path to Jadoo only if Jadoo helped him solve a problem which has been bothering him for many years. The problem is :

"We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, a 4-digit Pandigital number which is also a prime is 2143. What is the largest n-digit pandigital prime which is <= M? If there is none, print -1"

Input Format

The first line contains T, the number of test cases. This is followed by T lines, each containing M.

Output Format

Print the required answer for each test case.

Constraints

1 <= T <= 100000,
10 <= M <= 10^10 - 1

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
Tags:
Medium
Points:30
Tags:
Medium
Points:30
13 votes
Tags:
Binary search algorithmMediumRecruitPrime FactorizationSegment treeMathematicsOpenApprovedMathematicsMathamatics