1762B - Make Array Good

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值