#K94857. Maximum Cake Pieces
Maximum Cake Pieces
Maximum Cake Pieces
You are given an integer N
representing the number of straight cuts made on a cake. Your task is to determine the maximum number of pieces that can be obtained by making these cuts.
The result is computed using the formula:
$$\frac{N(N+1)}{2} + 1$$
For example, if N = 0
, the cake is not cut at all so there is only 1 piece. If N = 1
, the cake is divided into 2 pieces. Similarly, for N = 2
, the cake can be cut into 4 pieces, and so on.
You need to write a program that reads multiple test cases from standard input and outputs the result for each test case on a new line.
inputFormat
The first line contains a single integer T
representing the number of test cases. This is followed by T
lines, each containing one integer N
(where N ≥ 0
), representing the number of cuts on the cake.
Input Format:
T N1 N2 ... NT
outputFormat
For each test case, output a single line containing the maximum number of pieces that can be obtained by cutting the cake with N
straight lines.
3
0
1
2
1
2
4
</p>