PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000195. Số nguyên tố đối xứng

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Số nguyên tố đối xứng

Symmetric Primes

Source: LQDOJ ptnk1920symprime
Version: Phuoc Hung OJ Extended (one dataset per execution; batched queries remain together).

Problem Statement

Let p1=2,p2=3,p3=5,…p_1=2,p_2=3,p_3=5,\ldots be the primes in increasing order. A prime pip_i with neighbors pi−1,pi+1p_{i-1},p_{i+1} is symmetric if

pi=pi−1+pi+12.p_i=\frac{p_{i-1}+p_{i+1}}{2}.

Given tt queries nn, print YES if nn is a symmetric prime and NO otherwise.

Input

First line tt; then tt integers nn, one per line.

Output

Print YES or NO for each query, in the given order.

Subtasks

  • Subtask 1 (20 points): 1≤t≤301\le t\le30, 1≤n≤1041\le n\le10^4.
  • Subtask 2 (30 points): 1≤t≤50001\le t\le5000, 1≤n≤1061\le n\le10^6.
  • Subtask 3 (50 points): 1≤t≤1051\le t\le10^5, 1≤n≤2⋅1071\le n\le2\cdot10^7.

Sample Input

3
11
5
373

Sample Output

NO
YES
YES

Sample Explanation

55 is between consecutive primes 33 and 77 and equals (3+7)/2(3+7)/2. In contrast, 1111 does not equal the average of 77 and 1313.