#K54792. Alternating Series Generation
Alternating Series Generation
Alternating Series Generation
You are given a non-negative integer ( n ). Your task is to generate a sequence of ( n ) integers following a specified pattern. Specifically, for each integer ( i ) where ( 0 \leq i < n ), the ( i )-th element of the series is defined as follows:
[ a_i = \begin{cases} i & \text{if } i \text{ is even},\ -i & \text{if } i \text{ is odd}. \end{cases} ]
For example, if ( n = 5 ), the output should be: 0, -1, 2, -3, 4.
The input will be provided via standard input and your program should print the result to standard output. Ensure that the output sequence is presented as space-separated integers with no extra spaces at the beginning or end.
inputFormat
A single integer ( n ) is provided as input from standard input. It represents the number of terms of the series to generate.
outputFormat
Output the generated series as space-separated integers on a single line to standard output. If ( n = 0 ), output nothing.## sample
5
0 -1 2 -3 4