Computer Science, asked by bhavanibunny666, 1 month ago

Question 1

SUM of Absolutes
Alice's initial position is (0,0) and he can only move along X-axis. He has N moves to make and in each move, he will select one of the following
options:
1. Go to (X-1,0) from (X,0)
2. Go to (X+1,0) from (X,0)
3. Remain at his current position
Your task is to calculate (abs(X)+abs(Y) for all reachable (X,Y),
Note: Here, abs denotes the absolute value.
Input format
• The first line contains T denoting the number of test cases.
• The first line of each test case containing an integer N denoting the number of moves.
Output format
Print I lines. For each test case, print a single integer as described in the problem statement,
Copy
Sample output 1
Sample input 1
2
1
1​

Answers

Answered by som758987
1

SUM of Absolutes

Alice's initial position is (0,0) and he can only move along X-axis. He has N moves to make and in each move, he will select one of the following

options:

1. Go to (X-1,0) from (X,0)

2. Go to (X+1,0) from (X,0)

3. Remain at his current position

Your task is to calculate (abs(X)+abs(Y) for all reachable (X,Y),

Note: Here, abs denotes the absolute value.

Input format

• The first line contains T denoting the number of test cases.

• The first line of each test case containing an integer N denoting the number of moves.

Output format

Print I lines. For each test case, print a single integer as described in the problem statement,

Copy

Sample output 1

Sample input 1

2

1

1

  • MARK ME AS BRAINLIEST

Similar questions