Harry's Circular Primes

4.3

23 votes
Problem

Professor Dumbledore has asked Harry to find circular primes. A circular prime is a prime number with the property that the number generated at each intermediate step when cyclically permuting its (base 10) digits will be a prime. Simply if all the rotational digits of a number are themselves primes, it is called a circular prime number. For example,19937 is a circular prime as 19937,99371,93719,37199 and 71993 are primes. Help harry to find if the number is circular prime!

Input Format: The first line of the input contains an integer T denoting the number of test cases.T lines follows. Each testcase contains a number n for which you need to check whether it is circular prime or not.

Output Format: If a certain number is a circular prime print "Yes". If not a circular prime print "No".

Constraints: 1<=T<=10 0<=n<=10000000

Sample Input
3
3
113
67
Sample Output
Yes
Yes
No
Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?