NPS-INR-Codewars-2022

The 2022 edition of the NPS Indiranagar interhouse Cyber Programming contest.

View on GitHub

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:

Output format:

Constraints:

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)