CF1762B.Make Array Good

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

An array bb of mm positive integers is good if for all pairs ii and jj (1≤i,j≤m1 \leq i,j \leq m), max⁡(bi,bj)\max(b_i,b_j) is divisible by min⁡(bi,bj)\min(b_i,b_j).

You are given an array aa of nn positive integers. You can perform the following operation:

  • Select an index ii (1≤i≤n1 \leq i \leq n) and an integer xx (0≤x≤ai0 \leq x \leq a_i) and add xx to aia_i, in other words, ai:=ai+xa_i := a_i+x.
  • After this operation, ai≤1018a_i \leq 10^{18} should be satisfied.

You have to construct a sequence of at most nn operations that will make aa good. It can be proven that under the constraints of the problem, such a sequence of operations always exists.

一个由 mm 个正整数组成的数组 bb 被称为好数组,当且仅当对所有下标对 ii 和 jj(1≤i,j≤m1 \leq i,j \leq m),max⁡(bi,bj)\max(b_i,b_j) 都能被 min⁡(bi,bj)\min(b_i,b_j) 整除。

你被给定一个由 nn 个正整数组成的数组 aa。你可以执行以下操作:

  • 选择一个下标 ii(1≤i≤n1 \leq i \leq n)和一个整数 xx(0≤x≤ai0 \leq x \leq a_i),并将 xx 加到 aia_i 上,即令 ai:=ai+xa_i := a_i+x;
  • 执行该操作后,需满足 ai≤1018a_i \leq 10^{18}。

你需要构造一个最多包含 nn 次操作的操作序列,使得数组 aa 变为好数组。在本题约束条件下,可以证明这样的操作序列一定存在。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1051 \leq n \leq 10^5) — the length of the array aa.

The second line of each test case contains nn space-separated integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤1091 \leq a_i \leq 10^9) — representing the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5),表示数组 aa 的长度。

每个测试用例的第二行包含 nn 个以空格分隔的整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤ai≤1091 \leq a_i \leq 10^9),表示数组 aa。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

For each test, output a single integer pp (0≤p≤n0 \leq p \leq n) — denoting the number of operations in your solution.

In each of the following pp lines, output two space-separated integers — ii and xx.

You do not need to minimize the number of operations. It can be proven that a solution always exists.

对于每组测试,输出一个整数 pp(0≤p≤n0 \leq p \leq n),表示你解决方案中的操作次数。

接下来的 pp 行中,每行输出两个用空格分隔的整数:ii 和 xx。

你无需最小化操作次数。可以证明解总是存在的。

输入输出样例

  • 输入#1

    4
    4
    2 3 5 5
    2
    4 8
    5
    3 4 343 5 6
    3
    31 5 17

    输出#1

    4
    1 2
    1 1
    2 2
    3 0
    0
    5
    1 3
    1 4
    2 1
    5 4
    3 7
    3
    1 29
    2 5
    3 3

说明/提示

In the first test case, array aa becomes [5,5,5,5][5,5,5,5] after the operations. It is easy to see that [5,5,5,5][5,5,5,5] is good.

In the second test case, array aa is already good.

In the third test case, after performing the operations, array aa becomes [10,5,350,5,10][10,5,350,5,10], which is good.

In the fourth test case, after performing the operations, array aa becomes [60,10,20][60,10,20], which is good.

在第一个测试用例中,执行操作后数组 aa 变为 [5,5,5,5][5,5,5,5]。显然,[5,5,5,5][5,5,5,5] 是“好”的。

在第二个测试用例中,数组 aa 本身已经是“好”的。

在第三个测试用例中,执行操作后数组 aa 变为 [10,5,350,5,10][10,5,350,5,10],该数组是“好”的。

在第四个测试用例中,执行操作后数组 aa 变为 [60,10,20][60,10,20],该数组是“好”的。

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

首页