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.
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.
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.
1<= T <=100
13<= N <=100000
13 17 31 37 71 73 79 97
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.