#C9050. Palindromic Sequence Generation
Palindromic Sequence Generation
Palindromic Sequence Generation
You are given an integer N. Your task is to generate a palindromic sequence using the integers from 1 up to N if N is odd. The palindromic sequence is constructed by listing the numbers from 1 to m and then appending the mirror of the sequence (except the last number) so that the entire sequence forms a palindrome, where m = (N//2 + 1). If N is even, no palindromic sequence is possible and you should output an empty line.
For example:
- For N = 1, the output is:
1
- For N = 3, the output is:
1 2 1
- For N = 5, the output is:
1 2 3 2 1
- For N = 2 or any even number, the output is an empty line.
You will be given multiple test cases. For each test case, output the palindromic sequence in a single line. All numbers in the sequence should be separated by a single space.
The mathematical construction for an odd N can be expressed using LaTeX as follows:
$$\text{If }N\text{ is odd: } P = [1, 2, \dots, m, \dots, 2, 1] \quad \text{with } m = \frac{N+1}{2}. $$inputFormat
The first line of input contains an integer T representing the number of test cases. Each of the following T lines contains a single integer N.
Input Format:
T N1 N2 ... NT
outputFormat
For each test case, output a single line containing the palindromic sequence if N is odd, with each number separated by a space. If N is even, output an empty line.
Output Format:
Sequence1 Sequence2 ... SequenceT## sample
3
1
3
5
1
1 2 1
1 2 3 2 1
</p>