CF1521B.Nastia and a Good Array

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Nastia has received an array of nn positive integers as a gift.

She calls such an array aa good that for all ii (2≤i≤n2 \le i \le n) takes place gcd(ai−1,ai)=1gcd(a_{i - 1}, a_{i}) = 1, where gcd(u,v)gcd(u, v) denotes the greatest common divisor (GCD) of integers uu and vv.

You can perform the operation: select two different indices i,ji, j (1≤i,j≤n1 \le i, j \le n, i≠ji \neq j) and two integers x,yx, y (1≤x,y≤2⋅1091 \le x, y \le 2 \cdot 10^9) so that min⁡(ai,aj)=min⁡(x,y)\min{(a_i, a_j)} = \min{(x, y)}. Then change aia_i to xx and aja_j to yy.

The girl asks you to make the array good using at most nn operations.

It can be proven that this is always possible.

娜斯佳收到了一个由 nn 个正整数组成的数组作为礼物。

她称一个数组 aa 是“好的”,当且仅当对所有 ii(2≤i≤n2 \le i \le n)均满足 gcd⁡(ai−1,ai)=1\gcd(a_{i - 1}, a_{i}) = 1,其中 gcd⁡(u,v)\gcd(u, v) 表示整数 uu 和 vv 的最大公约数(GCD)。

你可以执行如下操作:选择两个不同的下标 i,ji, j(1≤i,j≤n1 \le i, j \le n,且 i≠ji \neq j)以及两个整数 x,yx, y(1≤x,y≤2⋅1091 \le x, y \le 2 \cdot 10^9),使得 min⁡(ai,aj)=min⁡(x,y)\min{(a_i, a_j)} = \min{(x, y)}。然后将 aia_i 修改为 xx,并将 aja_j 修改为 yy。

女孩请你至多使用 nn 次操作,使该数组变为“好的”。

可以证明,这总是可行的。

输入格式

The first line contains a single integer tt (1≤t≤10 0001 \le t \le 10\,000) — the number of test cases.

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

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_{n} (1≤ai≤1091 \le a_i \le 10^9) — the array which Nastia has received as a gift.

It's guaranteed that the sum of nn in one test doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤10 0001 \le t \le 10\,000),表示测试用例的数量。

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

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_{n}(1≤ai≤1091 \le a_i \le 10^9),即 Nastia 收到的数组礼物。

保证单个测试中所有 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each of tt test cases print a single integer kk (0≤k≤n0 \le k \le n) — the number of operations. You don't need to minimize this number.

In each of the next kk lines print 44 integers ii, jj, xx, yy (1≤i≠j≤n1 \le i \neq j \le n, 1≤x,y≤2⋅1091 \le x, y \le 2 \cdot 10^9) so that min⁡(ai,aj)=min⁡(x,y)\min{(a_i, a_j)} = \min{(x, y)} — in this manner you replace aia_i with xx and aja_j with yy.

If there are multiple answers, print any.

对于每个测试用例,输出一个整数 kk(0≤k≤n0 \le k \le n)—— 表示操作次数。你无需最小化该数值。

接下来的 kk 行中,每行输出四个整数 ii、jj、xx、yy(1≤i≠j≤n1 \le i \neq j \le n,1≤x,y≤2⋅1091 \le x, y \le 2 \cdot 10^9),使得 min⁡(ai,aj)=min⁡(x,y)\min{(a_i, a_j)} = \min{(x, y)} —— 据此,你将 aia_i 替换为 xx,并将 aja_j 替换为 yy。

若存在多个合法答案,输出任意一个即可。

输入输出样例

  • 输入#1

    2
    5
    9 6 3 11 15
    3
    7 5 13

    输出#1

    2
    1 5 11 9
    2 5 7 6
    0

说明/提示

Consider the first test case.

Initially a=[9,6,3,11,15]a = [9, 6, 3, 11, 15].

In the first operation replace a1a_1 with 1111 and a5a_5 with 99. It's valid, because min⁡(a1,a5)=min⁡(11,9)=9\min{(a_1, a_5)} = \min{(11, 9)} = 9.

After this a=[11,6,3,11,9]a = [11, 6, 3, 11, 9].

In the second operation replace a2a_2 with 77 and a5a_5 with 66. It's valid, because min⁡(a2,a5)=min⁡(7,6)=6\min{(a_2, a_5)} = \min{(7, 6)} = 6.

After this a=[11,7,3,11,6]a = [11, 7, 3, 11, 6] — a good array.

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

考虑第一个测试用例。

初始时 a=[9,6,3,11,15]a = [9, 6, 3, 11, 15]。

在第一次操作中,将 a1a_1 替换为 1111,同时将 a5a_5 替换为 99。该操作合法,因为 min⁡(a1,a5)=min⁡(11,9)=9\min{(a_1, a_5)} = \min{(11, 9)} = 9。

操作后,a=[11,6,3,11,9]a = [11, 6, 3, 11, 9]。

在第二次操作中,将 a2a_2 替换为 77,同时将 a5a_5 替换为 66。该操作合法,因为 min⁡(a2,a5)=min⁡(7,6)=6\min{(a_2, a_5)} = \min{(7, 6)} = 6。

操作后,a=[11,7,3,11,6]a = [11, 7, 3, 11, 6] —— 这是一个“好”数组。

在第二个测试用例中,初始数组已经是“好”数组。

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

首页