#K77412. Prime Distance Milestones
Prime Distance Milestones
Prime Distance Milestones
In this problem, you are given several test cases. In each test case, a driver passes through a series of milestones placed at increasing positions on a straight road. Your task is to determine the minimum number of consecutive milestones (including both endpoints) such that the distance between the first and last milestone is a prime number. Formally, if the milestones are denoted by an array (m[0], m[1], \ldots, m[N-1]), you need to find indices (i) and (j) (with (i < j)) for which the distance (d = m[j] - m[i]) is prime and the number of milestones involved, (j - i + 1), is minimized. If no such pair exists, output (-1).
inputFormat
The input begins with an integer (T) representing the number of test cases. Each test case consists of two lines. The first line contains an integer (N), the number of milestones. The second line contains (N) space-separated integers representing the positions of the milestones in strictly increasing order.
outputFormat
For each test case, output the minimum number of consecutive milestones (including both the starting and ending milestone) such that the distance between these two milestones is a prime number. If it is impossible to find such a pair, print (-1). The answer for each test case should be printed on a new line.## sample
3
5
2 3 5 7 11
4
10 20 30 40
6
1 3 6 10 15 21
2
-1
2
</p>