The Milky Way’s Chamber of Secrets
Problem Statement:
Mars is the head of a matrix of planets in the Milky Way. After Mars, many other planets were forming a triangle. It looks something like this:
0
2 4
6 8 10
12 14 16 18
20 22 24 26 28
and so on infinitely.
Can you make a code to sum up all the numbers in a given line N?
Input format:
- A single line of input containing the integer N
Output format:
- A single integer representing the sum of all numbers on the Nth row
Constraints:
- 1 ≤ N ≤ 104
Sample Input:
4
Sample Output:
60
Explanation:
The 4th row of the triangle is 12 14 16 18
. Sum of all the numbers in the 4th row is 12+14+16+18 = 60. Hence, 60 is the output.
Solution:
# Take input
n = int(input())
solution = (n-1) * n * (n+1)
print(solution)