An array bb of mm positive integers is good if for all pairs ii and jj (1≤i,j≤m1≤i,j≤m), max(bi,bj)max(bi,bj) is divisible by min(bi,bj)min(bi,bj).
You are given an array aa of nn positive integers. You can perform the following operation:
Select an index ii (1≤i≤n1≤i≤n) and an integer xx (0≤x≤ai0≤x≤ai) and add xx to aiai, in other words, ai:=ai+xai:=ai+x.
After this operation, ai≤1018ai≤1018 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.
Input
Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1041≤t≤104) — 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≤n≤105) — the length of the array aa.
The second line of each test case contains nn space-separated integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — representing the array aa.
It is guaranteed that the sum of nn over all test cases does not exceed 105105.
Output
For each test, output a single integer pp (0≤p≤n0≤p≤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.
题意:使数组中任意两个数都可以整除
可以用pair存数和位置,每次有三种情况,无论什么情况都使num达到当时最大 方便后面求倍数,最多n-1次
ai==ai-1,num=ai
ai<num, ai=num*2, num=ai
ai>num, ai=(ai/num+1)*num, num=ai
#include <bits/stdc++.h>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5 +10;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
pair<int, int> pii[N];
pair<int, int> pp[N];
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%lld", &pii[i].first);
pii[i].second = i + 1;
}
sort(pii, pii + n);
int j = 0;
long long num = pii[0].first;
for (int i = 1; i < n; i++)
{
if (pii[i].first == num)
continue;
else
{
if (pii[i].first % num == 0)
{
num = pii[i].first;
}
else if (pii[i].first < num)
{
j++;
pp[j].first = num - pii[i].first;
pp[j].second = pii[i].second;
}
else
{
j++;
pp[j].first = (pii[i].first / num + 1) * num - pii[i].first;
pp[j].second = pii[i].second;
num = (pii[i].first / num + 1) * num;
}
}
}
cout << j << "\n";
for (int i = 1; i <= j; i++)
{
cout << pp[i].second << " " << pp[i].first << "\n";
}
}
return 0;
}