F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Primality Test

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1130    Accepted Submission(s): 431


Problem Description
A positive integer is called a $\textit{prime}$ if it is greater than $1$ and cannot be written as the product of two smaller positive integers. A $\textit{primality test}$ is an algorithm for determining whether an input number is a prime. For example, the Miller-Rabin primality test is a probabilistic primality test. This problem is precisely the one about the primality test.

Let's define the function $f(x)$ as the smallest prime which is strictly larger than $x$. For example, $f(1)=2$, $f(2)=3$, and $f(3)=f(4)=5$. And we use $\lfloor x \rfloor$ to indicate the largest integer that does not exceed $x$.

Now given $x$, please determine whether $g(x)$ is a prime.

$$g(x)=\left\lfloor\dfrac{f(x)+f(f(x))}{2}\right\rfloor$$
 

Input
The first line of the input contains an integer $T$ ($1 \le T \le 10^5$), indicating the number of test cases.

Each test case contains an integer $x$ ($1 \le x \le 10^{18}$) in a single line.
 

Output
For each test case, if $g(x)$ is a prime, output $\texttt{YES}$ in a single line. Otherwise, output $\texttt{NO}$ in a single line.
 

Sample Input
2 1 2
 

Sample Output
YES NO
 

Hint

When $x=1$, $f(x)=2$, $f(f(x))=f(2)=3$, then $g(x)=\left\lfloor\dfrac{2+3}{2}\right\rfloor=2$, which is a prime. So the output is $\texttt{YES}$.

When $x=2$, $f(x)=3$, $f(f(x))=f(3)=5$, then $g(x)=\left\lfloor\dfrac{3+5}{2}\right\rfloor=4$, which is not a prime. So the output is $\texttt{NO}$.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 04:16:00, Gzip enabled