#C8221. Prime Palindrome Check

    ID: 52180 Type: Default 1000ms 256MiB

Prime Palindrome Check

Prime Palindrome Check

Given an integer, determine whether it is both a prime number and a palindrome.

A prime number is defined as an integer \(n\) greater than 1 that has no positive divisors other than 1 and \(n\) itself. A palindrome is a number that remains the same when its digits are reversed, for example \(121\) or \(131\).

Your task is to check each input number and print YES if it satisfies both properties and NO otherwise.

Formally, for each test case with integer \(n\):

  • If \(n > 1\), \(n\) is prime, and \(n\) reads the same backward as forward, output YES.
  • Otherwise, output NO.

All formulas are written in LaTeX, e.g., a number \(n\) is prime if \(n>1\) and for every integer \(k\) with \(2 \leq k \leq \sqrt{n}\), \(n \mod k \neq 0\).

inputFormat

The input is given from stdin and has the following format:

T
n1
n2
... 
 nT

Where:

  • T (1 ≤ T ≤ 105) is the number of test cases.
  • Each of the next T lines contains an integer n (0 ≤ n ≤ 109).

outputFormat

For each test case, output the answer on a new line to stdout:

YES
NO
...

Print YES if the given number is both prime and a palindrome; otherwise, print NO.

## sample
3
11
101
10
YES

YES NO

</p>