原题链接; http://codeforces.com/contest/1438/problem/A
测试样例
input
3
1
2
4
output
24
19 33
7 37 79 49
Note
Array [19,33] is perfect as all 3 its subarrays: [19], [33], [19,33], have sums divisible by their lengths, and therefore are good.
题意: 定义一个好数组如下:
如果一个数组的和能整除这个数组的长度,那么这个数组就是好数组。
现在你需要构建长度为 n n n的这个的一个数组 a a a,它的子序列都满足好子数组的条件。
解题思路: 一道构造问题,看起来比较难,但我们想想是放在div2中的A题,便可以想到应该是有特殊的构造方法。我们来想一想,如果一个数组中的所有元素都是相同的,那么这个数组是不是必是好数组,假设数组元素为 a a a,那么对于长度为 n n n的数组其和必为 n ∗ a n*a n∗a,必能整除。 所以我们只要构建一个长度为 n n n的所有元素都相同的 a a a数组即可。
AC代码
/*
*邮箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何问题请私信我或评论区留言,谢谢支持。
*
*/
#include<bits/stdc++.h>//POJ不支持
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=a;i>=n;i--)
using namespace std;
const int inf=0x3f3f3f3f;//无穷大。
const int maxn=1e5;//限定值。
typedef long long ll;
int t,n;
int main(){
while(cin>>t){
while(t--){
cin>>n;
rep(i,0,n-1){
cout<<"1 ";
}
cout<<endl;
}
}
return 0;
}