Problem - B - Codeforces
给定那个数,可以使用操作选择i,j两个位置使得a[i] = (a[i] / a[j])(上取整),求出操作数,和每次操作的位置
#include <bits/stdc++.h>
#include <iostream>
#include<unordered_map>
#include<unordered_set>
#define x first
#define y second
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
typedef pair<int,int> PII ;
typedef pair<LL,int> PLI ;
const int N = 2e5+ 10 ;
const LL INF2 = 1e17;
int n,m,q;
inline void solve()
{
cin >> n;
vector<int> a(n);
int cnt1 =0 ;
for(int &x:a) {
cin >> x; cnt1 += (x == 1 );
}
if(a == vector<int>(n,a[0]))//每个数都一样,不用操作
{
cout << 0 << "\n";
return;
}
if(cnt1){cout << -1 << "\n";return;} //有1个1其他数不完全是1,其他数无论怎么操作结果都是大于 1
vector<PII> ans;
while(a != vector<int>(n,a[0]))
{
int x=0,y=1;
while(a[y] == a[x]) y ++;
if(a[x] < a[y]) swap(x,y);
a[x] = (a[x] + a[y] -1 ) / a[y];
ans.push_back({x+1,y+1});
}
cout<<ans.size() << "\n";
for(PII t :ans) cout<<t.x << " " << t.y << '\n';
}
signed main()
{
ios
int T=1;
cin>>T;
while(T -- )
{
solve();
}
return 0;
}