CF453B.Little Pony and Harmony Chest

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Princess Twilight went to Celestia and Luna's old castle to research the chest from the Elements of Harmony.

A sequence of positive integers b__i is harmony if and only if for every two elements of the sequence their greatest common divisor equals 1. According to an ancient book, the key of the chest is a harmony sequence b__i which minimizes the following expression:

You are given sequence a__i, help Princess Twilight to find the key.

暮光公主前往塞拉斯蒂娅与露娜的旧城堡,研究来自和谐之元的宝箱。

一个正整数序列 bib_i 被称为和谐序列,当且仅当该序列中任意两个元素的最大公约数均为 1。根据一本古籍记载,宝箱的钥匙即为一个和谐序列 bib_i,使得下列表达式的值最小:

现给出序列 aia_i,请帮助暮光公主找出该钥匙。

输入格式

The first line contains an integer n (1 ≤ n ≤ 100) — the number of elements of the sequences a and b. The next line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 30).

第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)—— 序列 aa 和 bb 的元素个数。
接下来的一行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤301 \leq a_i \leq 30)。

输出格式

Output the key — sequence b__i that minimizes the sum described above. If there are multiple optimal sequences, you can output any of them.

输出使上述和最小的关键序列 bib_i。如果存在多个最优序列,输出其中任意一个即可。

输入输出样例

  • 输入#1

    5
    1 1 1 1 1

    输出#1

    1 1 1 1 1
  • 输入#2

    5
    1 6 4 2 8

    输出#2

    1 5 3 1 8

输入解题思路,AI测评打分。不知道怎么写?

首页