原题链接: http://codeforces.com/contest/1447/problem/A
测试样例
input
2
2
3
output
1
2
5
3 3 3 1 2
Note
In the first case, adding 1 candy to all bags except of the second one leads to the arrangement with [2,2] candies.
In the second case, firstly you use first three operations to add 1+2+3=6 candies in total to each bag except of the third one, which gives you [7,8,3]. Later, you add 4 candies to second and third bag, so you have [7,12,7], and 5 candies to first and third bag — and the result is [12,12,12].
题意: 你有个包,第
个包中有
个糖果,现在你可以进行
个操作,其中第
个操作表述为选择一个包,使得除这个包之外所有的包中的糖果都加上
个糖果,现在你需要使得每个包中的糖果都相同。(不必在乎
个大小)
解题思路: 这是一道思维题,也相当于找规律的题,不要被样例迷惑了。我们发现,如果我们进行个操作,其中在第
个操作中刚好选择第
个包,那么最后所有的包的糖果都是
个,都是相等的。 这即是正确答案。
AC代码
/*
*
*/
//POJ不支持
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;
cout<<n<<endl;
rep(i,1,n){
cout<<i<<" ";
}
cout<<endl;
}
}
return 0;
}