D. Little Pony and Harmony Chest
Princess Twilight went to Celestia and Luna's old castle to the chest from the Elements of Harmony.
A sequence of positive integers bi was harmony if and only if for every II elements of the Seque nCE their greatest common divisor equals 1. According to an ancient book, the key of the chest is a harmony sequence bi which minimizes The following expression:
You is given sequence ai, help Princess Twilight to find the key.
Input
The first line contains an integer n (1≤ n ≤100)-the number of elements of the sequences c11>a and b. The next line contains n integersa1, a2, ..., a n (1≤ ai ≤30).
Output
Output the key-sequence bi that minimizes the sum described above. If there is multiple optimal sequences, you can output any of them.
Test instructions
Give you a length of not more than 100 of array A, the array B to make the corresponding element difference and the smallest, and B array 22 elements coprime.
It is easy to see that the maximum value of b[i] will not exceed 58, 59 can be used but 59 is why not 1.
Using Mask[i] to represent the quality factor of I, such as mask[6] = 3
Dp[i][mask[j]|k] = min (Dp[i-1][j] + ABS (A[i]-K)) indicates that the pre-I number has been selected in the state of the mass factor is mask[j]|k, the transfer time to ensure that mask[j] & k = = 0,
Then record the transfer process (in order to output B), and then it's done.
Codeforces Round #259 (Div. 2) D. Little Pony and Harmony Chest pressure DP