XOR = Average
title
/contest/1758/problem/B
key idea
Given an integer n, to makeDissimilarity of n numbers
= Average of the sum of n numbers
which outputs the n numbers
reasoning
When n is an odd number
The differentiation of n identical numbers (let's say a) is also a, and the average of the sum of the n a's is also a.
When n is an even number
The dissimilarity of n identical numbers (let's say a) is 0, so toConvert to an odd number of identical numbersThe result of such an anomaly is a , butTo make the average of the sum of these numbers also aI'm going to have to letConverse of the sum of the two numbers being converted = (sum of the two numbers) / 2
, so that the average value is this dissimilarity. The smallest two numbers that satisfy this condition are 1 and 3 (the dissimilarity between 1 and 2 is 3, (1 + 2) / 2 ! = 3 so it is not satisfied)
1 3 2 2 ....
coding
#include <iostream>
using namespace std;
int main()
{
int t; cin >> t;
while(t--)
{
int n; cin >> n;
if(n & 1) //nodd-numbered
while(n--) cout << 1 << ' ';
else //neven number
{
cout << 1 << ' ' << 3 << ' ';
int num = n - 2;
while(num--) cout << 2 << ' ';
}
cout << endl;
}
}