#P2682. Tree

    ID: 1579 远端评测题 2000ms 32MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>2009浙江大学计算机研考复试(机试部分)——全真模拟

Tree

Problem Description

There are N (2<=N<=600) cities,each has a value of happiness,we consider two cities A and B whose value of happiness are VA and VB,if VA is a prime number,or VB is a prime number or (VA+VB) is a prime number,then they can be connected.What's more,the cost to connecte two cities is Min(Min(VA , VB),|VA-VB|).
Now we want to connecte all the cities together,and make the cost minimal.

Input

The first will contain a integer t,followed by t cases.
Each case begin with a integer N,then N integer Vi(0<=Vi<=1000000).

Output

If the all cities can be connected together,output the minimal cost,otherwise output "-1";

2 5 1 2 3 4 5

4 4 4 4 4

</p>
4 -1

Author

Teddy