forked from sureshmangs/Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1521B - Nastia and a Good Array.cpp
87 lines (56 loc) · 2.16 KB
/
1521B - Nastia and a Good Array.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
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=105) — the length of the array.
The second line of each test case contains n integers a1,a2,…,an (1=ai=109) — 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.
*/
#include<bits/stdc++.h>
using namespace std;
#define m 1000000007
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector <int> v(n);
for (auto &x: v) cin >> x;
cout << n / 2 << endl;
for (int i = 0; i < n - 1; i+= 2) {
cout << i + 1 << " " << i + 2 << " " << min(v[i], v[i + 1]) << " " << m << endl;
}
}
return 0;
}