A Prime Array is an array which doesn't contain a pair of numbers whose product is a square of an integer.

For eg [1,2,3] is a Prime Array but [1,2,4] is not.

Explanation : 1*4 gives 4 which is square of 2.

Given an array of integers determine the minimum number of operations to convert the array to a Prime array.

NOTE: An operation consists of either increasing or decreasing any element of the array by 1 but the element should always be positive.

Constraints: Length of array <=100

1 <=Each integer in array <=1000000

Eg. Array => [1,1,2]

Minimum operations to convert [1,1,2] to [1,2,3] is 2.

The problem can be formulated as follows.

Given an integer array

A= [a_{1},a_{2}, ...,a_{n}], where 1 ≤n≤ 100, and 1 ≤a_{i}≤ 10^{6}, find an integer arrayD= [d_{1},d_{2}, ...,d_{n}] such that:d_{i}> -a_{i}for all 1 ≤i≤nThe array

B=A+D, whereb_{i}=a_{i}+d_{i}, is Prime, andThe objective function is minimized.

The following are few hints that may be helpful in solving the problem:

An array

Bwithn= 1 is Prime for any value of its element.A Prime array

Bwithn> 1 should have distinct elements.A Prime array

Bwithn> 1 should have at most one element that is a square of an integer.A Prime array

Bwithn> 1 should have distinct odd-power prime factors for each element. For example, an array that contains 150 and 294 in not Prime, because both elements have the same odd-power prime factors 2 and 3, 150 = 2 x 3 x 5 x 5 and 294 = 2 x 3 x 7 x 7, and their multiplication 150 x 294 = 44100 is guaranteed to be square. In this example, 44100 = 210 x 210 and 210 = 2 x 3 x 5 x 7. Note that any square of an integer should have no odd-power prime factors, as all powers of its prime factors should be even numbers.The answer does not depend on the order of the elements in the array. Therefore, sorting the array when

n> 1 may be a good approach to reduce the computational complexity of the solution.P.S. Just a kind reminder to what several members of the Codeforces Community indicated before: a link to the problem statement should be provided in the blog if possible, and the problem should not be presently in a running contest.

This was a Coding Contest problem while interviewing for a company so there are no links available.