Nastia has received an array of n positive integers as a gift.
She calls such an array a good that for all i (2≤i≤n) takes place gcd(ai−1,ai)=1, where gcd(u,v) denotes the greatest common divisor (GCD) of integers u and v.
You can perform the operation: select two different indices i,j (1≤i,j≤n, i≠j) and two integers x,y (1≤x,y≤2^109) so that min(ai,aj)=min(x,y). Then change ai to x and aj to y.
The girl asks you to make the array good using at most n operations.
It can be proven that this is always possible.
Input
The first line contains a single integer t (1≤t≤10000) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤10^5) — the length of the array.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤10^9) — the array which Nastia has received as a gift.
It’s guaranteed that the sum of n in one test doesn’t exceed 2^105.
Output
For each of t test cases print a single integer k (0≤k≤n) — the number of operations. You don’t need to minimize this number.
In each of the next k lines print 4 integers i, j, x, y (1≤i≠j≤n, 1≤x,y≤2^109) so that min(ai,aj)=min(x,y) — in this manner you replace ai with x and aj with y.
If there are multiple answers, print any.
Example
inputCopy
2
5
9 6 3 11 15
3
7 5 13
outputCopy
2
1 5 11 9
2 5 7 6
0
Note
Consider the first test case.
Initially a=[9,6,3,11,15].
In the first operation replace a1 with 11 and a5 with 9. It’s valid, because min(a1,a5)=min(11,9)=9.
After this a=[11,6,3,11,9].
In the second operation replace a2 with 7 and a5 with 6. It’s valid, because min(a2,a5)=min(7,6)=6.
After this a=[11,7,3,11,6] — a good array.
In the second test case, the initial array is already good.
因为不需要求出最少的操作次数,而需要保留每相邻两组中的最小的数,所以改变所有的数除了最小的数。
1)
即,需要操作n - 1次,
相邻两个,每个不管是否符合gcd都去操作,那么就要操作n - 1次。
2)
因为在1)的操作下,min最终会被保留下来,所以把min及其下标保留,变更其他的数字,使其gcd = 1。
3)
要想gcd = 1,两个数的差为1,是最简单的,比如1和2, 3和4等等。
也就需要保证相邻两个数之差是1.
4)
通过下标处理,用min的下标index与其他数的下标差相减,再加上min,可以保证相邻的两个数的差为1;
假设第三个数是最小的且为5,
那么第一个数改为,3 - 1 + 5 = 7,
第二个数改为, 3 - 2 + 5 = 6.
min下标index分别与相邻两个数的下标差也相差1;
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while(t--) {
int n;
scanf("%d", &n);
//这个之前放在循环外面导致一直没通过,每次循环都要重新更新数据
int min = 2000000000;
int index = -1;
for(int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
if(a < min) {//找到最小的数和他的下标
min = a;
index = i;
}
}
printf("%d\n", n - 1);
for(int i = 0; i < n; i++) {
if(i == index) {
continue;
} else {
printf("%d %d %d %d\n", index + 1, i + 1, min, min + abs(i - index));
}
}
}
return 0;
}