Prime number definition: An integer greater than 1, if its approximate number is only 1 and it itself, then it is a prime number.

Palindrome definition: An integer to the number of its numbers upside down or it itself, then it is a palindrome number, for example, 2, 99,393.

Palindrome Prime definition: If a number is both prime and palindrome number, then we call it a palindrome number, for example, say: 7, 11,131.

Now that we have n numbers, you need to determine if they are palindrome primes.

"Input Format"

The first line is only one number n (n<100), which is the number of numbers to judge.

The next n rows, each row has a number x (x<1,000,000,000), which is the number you want to judge.

"Output Format"

There are n rows, one word per line, and for each x, if X is a palindrome prime, output "Yes", otherwise output "no" (not including quotation marks, note case).

"Input Sample"

3

7

12

121

"Output Example"

Yes

No

No

"Data Range"

40% Data: n<=10,x<1,000

70% Data: n<=50,x<100,000

100% Data: n<100,x<1,000,000,000

Hint

The judgment of palindrome number, the judgment of Prime.

An algorithm for optimizing prime number judgments.

It's mine

1#include <stdio.h>2#include <math.h>//sqrt () need to use this header file, MO forget!!! 3 intMain () {4 Long LongN, sum =0, x, I;//the maximum value of long long: 92233720368547758075 intFlag =0, Yu;//minimum value of Longlong: -92233720368547758086scanf"%lld", &n);//note for%lld, often forget7 while(n--) {8scanf"%lld", &x);9 Long LongZhong = sqrt (x);//originally wanted to use X/2, the result will be timed out, so with the most correct algorithmTen for(i =2; I <= Zhong; i++) { One if(x% i = =0) { AFlag =1; - Break; - } the } - for(i = x; I! =0; I/=Ten) {//The way to reverse the numbers . -Yu = i%Ten; -sum = SUM *Ten+Yu; + } - if(Sum! =x) +Flag =1; A if(Flag = =0) atprintf"yes\n"); - Else -printf"no\n"); -Flag =0; -sum =0; - } in return 0; -}

Algorithms for solving palindrome numbers:

An integer puts its numbers upside down or is it itself, so the main is to turn the numbers upside down

For example, the number you entered is 12321:

Before the cycle begins: m=12321,sum=0;

1th cycle end: M=1232,sum=1;

2nd cycle End: M=123,sum = 12;

3rd cycle end: m=12,sum=123;

4th cycle end: m=1,sum=1232;

End of the 5th cycle: m=0,sum=12321.

Enter a number of digits to loop a few times.

The idea of judgment is, through the cycle of the M-bit, 10 bits, hundred ... The number above is taken out and added to the sum*10. So the sum of sums is the number after the reversal of M, if the two are equal, that is the palindrome number.

[1008]harder_prime