当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7129:Primality Test

题目描述
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$$
输入解释
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.
输出解释
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.
输入样例
2
1
2
输出样例
YES
NO
来自杭电HDUOJ的附加信息
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}$.

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7129

最后修改于 2021-10-23T19:11:38+00:00 由爬虫自动更新

共提交 3

通过率 0.0%
时间上限 内存上限
10000/5000MS(Java/Others) 262144/262144K(Java/Others)