Codeforces Round #259 (Div. 2) D. Little Pony and Harmony Chest pressure DP

Source: Internet
Author: User
Tags greatest common divisor

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.