NUMPYR - editorial

[Problem][1]

[Contest][2]

DIFFICULTY

Easy/Medium

PREREQUISITES

Basic Mathematics, Knowledge of Permutations and Combinations

PROBLEM

Identify the logic used to generate the series
9,48,117,216,345,504. . .
Use this logic to generate a pyramid. The base of the pyramid should be the widest, converging towards the top. The top will have only one element. Each layer of the pyramid will have one element less than the layer underneath it. The input is N, which is the number of elements in the last layer.

QUICK EXPLANATION

Using simple Mathematics, we can find the standard formula for the series. Next, by using a loop, we can print the series up to a given number of columns.

EXPLANATION

To generate the series, we’ll have to derive the standard formula. For that we first divide all numbers by 3. We get the series
3 16 39 72 115 168

The series above now simplifies the problem. Now the standard formula for the above series is

n * ( 5 * n - 2 )

So the formula for the original series is

num = 3*n (5n - 2)

To print the pattern,

1. for i = 0 to i  < N; i++
    a. print blank space for (N- i - 1) times
    for j = 0 to j <= i ; j++ 
            a. n = ( i + j +1 ) * 2 
        b. num =  3 * n  * ( 5 * n  - 2 )  
        c. if number of digit in num < 5
               print 0 for (number of digit in num - 5) times
        d. print num
        e. if (  j < i )
               print space


  [1]: https://www.codechef.com/problems/NUMPYR
  [2]: https://www.codechef.com/BYCR2016/problems/NUMPYR