显然,容易构造n+20步完成.而在多出5步的情况下考虑每次保留sqrt(n)
按照下面进行构造:
\([1,2,3,4,5,6,7,8,9] to [1,2,3,1,1,1,1,1,9] to [1,2,3,1,1,1,1,1,3] to [1,2,3,1,1,1,1,1,1]...\)
tips: +20 考虑按二进制, +5 考虑按根号分块
const int maxn = 2e5 + 7;
#define int long long
int n, t, m;
vector<pair<int, int>> vec;
vector<vector<pair<int, int>>> ans;
int a[maxn];
void solve() {
cin >> t;
while (t--) {
cin >> n;
vec.clear();
ans.clear();
int now = n;
for (int i = n - 1; i >= 2; i--) {
if (i * i > now) {
vec.push_back({i, i + 1});
} else {
reverse(all(vec));
ans.push_back(vec);
vec.clear();
ans.push_back({{n, i}});
now = (now + i - 1) / i;
vec.push_back({i, n});
}
}
for (int i = 1; i <= n; i++)
a[i] = i;
vector<pair<int, int>> vec;
for (auto v:ans)
for (auto i :v)
vec.push_back(i);
vec.push_back({n, 2});
vec.push_back({n, 2});
vec.push_back({3, 2});
vec.push_back({3, 2});
cout << vec.size() << endl;
for (auto i :vec) {
// a[i.first] = (a[i.first] + a[i.second] - 1) / a[i.second];
cout << i.first << " " << i.second << endl;
}
// for (int i = 1; i <= n; i++)
// cout << a[i] << " ";
}
}