D. Range = √Sum

D. Range = √Sum

You are given an integer n. Find a sequence of n distinct integers a1,a2,,an such that 1ai109 for all i and max(a1,a2,,an)min(a1,a2,,an)=a1+a2++an.

It can be proven that there exists a sequence of distinct integers that satisfies all the conditions above.

Input

The first line of input contains t (1t104) — the number of test cases.

The first and only line of each test case contains one integer n (2n3105) — the length of the sequence you have to find.

The sum of n over all test cases does not exceed 3105.

Output

For each test case, output n space-separated distinct integers a1,a2,,an satisfying the conditions in the statement.

If there are several possible answers, you can output any of them. Please remember that your integers must be distinct!

Example

input

3
2
5
4

output

3 1
20 29 18 26 28
25 21 23 31

Note

In the first test case, the maximum is 3, the minimum is 1, the sum is 4, and 31=4.

In the second test case, the maximum is 29, the minimum is 18, the sum is 121, and 2918=121.

For each test case, the integers are all distinct.

 

解题思路

  构造题感觉更多是看直觉和灵感的,这里就直接按照题解的思路来写了。

  对于n是奇数的情况,我们可以考虑以n为中心往两边构造出序列{nn2,nn21,,n1,n,n+1,,n+n21,n+n2}

  此时序列的maxmin=n1,总和为(两端两两相加)n2×2n+n=n12×2n+n=n2。此时如果给序列中的每个数都加上2,那么maxmin=n1不变,总和变成了n12×2(n+2)+(n+2)=n2+2n。现在我们对序列中的最小值减去1,最大值加上1,此时maxmin=n+1,总和依然是n2+2n

  为了使得(n+1)2=n2+2n+1,我们再对序列中第二大的数加上1就可以了(由于上一步已经让最大数加1了,因此对第二大数加1得到的结果是合法的)。

  例如当n=5

  • [3,4,5,6,7](以5为中心构造)
  • [5,6,7,8,9](所有元素加2
  • [4,6,7,8,10](最小值减1,最大值加1
  • [4,6,7,9,10](第二大值加1

  对于n是偶数的情况,同样考虑以n为中心(不包含n)往两边构造出序列{nn2,nn21,,n1,n+1,,n+n21,n+n2}

  此时序列的maxmin=n,总和为n2×2n=n2

  AC代码如下:

复制代码
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 
 4 const int N = 3e5 + 10;
 5 
 6 int a[N];
 7 
 8 void solve() {
 9     int n;
10     scanf("%d", &n);
11     if (n & 1) {
12         for (int i = 0, j = n - n / 2; i < n; i++) {
13             a[i] = j++ + 2;
14         }
15         a[0]--, a[n - 1]++, a[n - 2]++;
16     }
17     else {
18         for (int i = 0, j = n - n / 2; i < n; i++) {
19             a[i] = j++;
20             if (j == n) j++;
21         }
22     }
23     for (int i = 0; i < n; i++) {
24         printf("%d ", a[i]);
25     }
26     printf("\n");
27 }
28 
29 int main() {
30     int t;
31     scanf("%d", &t);
32     while (t--) {
33         solve();
34     }
35     
36     return 0;
37 }
复制代码

  cf的构造题还是经常无从下手,寒假需要多做这样的题进行训练。现在也准备期末了,没时间打cf和写题解了,寒假再开始吧(我真的好菜)。・゚゚*(>д<)*゚゚・。

 

参考资料

  Codeforces Round #836 (Div. 2) Editorial:https://codeforces.com/blog/entry/109438

posted @   onlyblues  阅读(141)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探
· 为什么 退出登录 或 修改密码 无法使 token 失效
Web Analytics
点击右上角即可分享
微信分享提示