题意:
思路:先钦定这个序列的和为4n^{2} ,那么差值就是2n
考虑一个初始序列1,2,3,⋯,n−1,2n+1.现在我们要做的就是将这个序列变成合法的我可以进行整体都+x的操作使得这个序列的和尽量逼近4n^{2}。直接算出每个数应该加上的x,还会有一点剩余,加到a[n-1]上即可,a[n-1]+n==a[n],而剩余数<n,显然他们不会相等,构造完成。
#include <bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using PII = pair<i64, i64>;
const int inf = 0x3f3f3f3f;
const i64 INF = 0x3f3f3f3f3f3f3f3f;
#define Z cout << "\n"
#define lb lower_bound
#define ub upper_bound
#define D(x) cerr << #x << ": " << (x) << "\n"
#define DV(v) cerr<<#v<<": ";for(int i=0;i<(v).size();i++)cerr<<((v)[i])<<",";cerr<<"\n"
#if 1
#define int i64
#endif
signed main() {ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);int t;cin >> t;while (t--) {int n;cin >> n;vector<int>a(n + 5);for (int i = 1; i <= n - 1; i++)a[i] = i;a[n] = 2 * n + 1;int S = 4 * n * n;int sum = 0;for (int i = 1; i <= n; i++)sum += a[i];int d = (S - sum) / n;int s = (S - sum) - d * n;for (int i = 1; i <= n; i++)a[i] += d;a[n - 1] += s;for (int i = 1; i <= n; i++)cout << a[i] << ' ';Z;}return 0;
}