[Solution] Sign Moves solution codechef

Sign Moves solution codechef – Initially, Chef is at coordinate 00 on X-axis. For each i=1,2,…,Ni=1,2,…,N in order, Chef does the following:

  • If Chef is at a non-negativecoordinate, he moves ii steps backward (i.e, his position’s coordinate decreases by ii), otherwise he moves ii steps forward (i.e, his position’s coordinate increases by ii).

Sign Moves solution codechef

You are given the integer NN. Find the final position of Chef on the X-axis after NN operations.

Input Format

  • The first line of input contains an integer TT, denoting the number of test cases. The TTtest cases then follow:
  • The first and only line of each test case contains an integer NN.

Output Format

For each test case, output in a single line the final position of Chef on the X-axis after NN operations.


  • 1≤T≤1051≤T≤105
  • 1≤N≤1091≤N≤109

Sign Moves solution codechef





Sample Output 1 




Sign Moves solution codechef

Test case 11: Initially, Chef is at coordinate 00 on X-axis. As 00 is non-negative, during the first operation Chef moves 11 step backward and reaches the coordinate −1−1.

Test case 22: Chef is at coordinate −1−1 on X-axis after the first operation. As −1−1 is negative, during the second operation Chef moves 22 steps forward and reaches the coordinate 11.


For Solution

Click Here

Leave a Comment