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

Yes, Prime Minister

Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1262    Accepted Submission(s): 428


Problem Description
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$.
 

Input
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.
 

Output
For each test case, you need to output the minimal number of people kept if such a plan exists, output $-1$ otherwise.
 

Sample Input
10 -2 -1 0 1 2 3 4 5 6 7
 

Sample Output
6 4 3 2 1 1 2 1 2 1
 

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-04-20 08:49:42, Gzip enabled