Emirp numbers
Easy Accuracy: 16.79% Submissions: 387 Points: 2

Emirp is the word “prime” spelled backwards, and it refers to a prime number that becomes a new prime number when you reverse its digits. Emirps do not include palindromic primes (like 151 or 787) nor 1-digit primes like 7. Given a number n, the task is to print all such prime numbers from 13 to n  whose reversed number formed is also a prime number and smaller than or equal to n.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. The first line of each test case contains the integer N.

Output:
Print all Emirp numbers smaller than or equal to n in sorted order with space between two numbers. Print the answer for each test case in a new line. 

Constraints:
1 <= T <= 100
13 <= N <= 105

Example:
Input:
2
40
100

Output:
13 31
13 17 31 37 71 73 79 97

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.