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

建议使用的浏览器:

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

7025:Yes, Prime Minister

题目描述
Mr. Hacker's Department of Administrative Affairs (DAA) has infinite civil servants. Every integer is used as an id number by exactly one civil servant. Mr. Hacker is keen on reducing overmanning in civil service, so he will only keep people with consecutive id numbers in $[l,r]$ and dismiss others.

However, permanent secretary Sir Humphrey's id number is $x$ and he cannot be kicked out so there must be $l \leq x \leq r$. Mr. Hacker wants to be Prime Minister so he demands that the sum of people's id number $\sum_{i=l}^r i$ must be a prime number.

You, Bernard, need to make the reduction plan which meets the demands of both bosses. Otherwise, Mr. Hacker or Sir Humphrey will fire you.

Mr. Hacker would be happy to keep as few people as possible. Please calculate the minimum number of people left to meet their requirements.

A prime number $p$ is an integer greater than $1$ that has no positive integer divisors other than $1$ and $p$.
输入解释
The first line contains an integer $T(1 \leq T \leq 10^6)$ - the number of test cases. Then $T$ test cases follow.

The first and only line of each test case contains one integer $x_i (-10^7 \leq x_i \leq 10^7)$ - Sir Humphrey's id number.
输出解释
For each test case, you need to output the minimal number of people kept if such a plan exists, output $-1$ otherwise.
输入样例
10
-2
-1
0
1
2
3
4
5
6
7
输出样例
6
4
3
2
1
1
2
1
2
1

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

源链接: HDU-7025

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

共提交 0

通过率 --%
时间上限 内存上限
10000/10000MS(Java/Others) 524288/524288K(Java/Others)