아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Yes, Prime Minister

시간 제한10초메모리 제한512 MB

요약
각 x에 대해 x를 포함하면서 연속한 정수의 합이 소수가 되는 가장 짧은 구간 [l, r]의 길이를 구하고, 없으면 -1을 출력한다.
난이도

보통10점 중 4점

유형
수학, 정수론, 완전 탐색
정답자
아직 제출이 없습니다

문제

Mr. Hacker's Department of Administrative Affairs (DAA) has an infinite amount of civil servants. Every integer is used as an ID (identification number) by exactly one civil servant. Mr. Hacker is keen on reducing overmanning in civil service, so he will only keep people with consecutive IDs in \[l,r]\[l, r], and dismiss all the others.

However, permanent secretary Sir Humphrey's ID is xx, and he cannot be kicked out, so l≤x≤rl \leq x \leq r must hold. Mr. Hacker wants to be Prime Minister, so he demands that the sum of people's IDs ∑_i=lri\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 pp is an integer greater than 11 that has no positive integer divisors other than 11 and pp.

입력

The first line contains an integer TT (1≤T≤1061 \leq T \leq 10^6), the number of test cases. Then TT test cases follow.

The first and only line of each test case contains one integer x_ix\_i (−107≤x_i≤107-10^7 \leq x\_i \leq 10^7), the ID of Sir Humphrey.

출력

For each test case, print a line with one integer: the minimal number of people kept if such a plan exists, or −1-1 otherwise.

예제1

  1. 예제 1

    입력
    10
    -2
    -1
    0
    1
    2
    3
    4
    5
    6
    7
    
    예상 출력
    6
    4
    3
    2
    1
    1
    2
    1
    2
    1