Array ( [0] => [1] => questions [2] => Codevita-Previous-Questions [3] => LOGIC-PYRAMID ) Codevita Previous Questions | LOGIC PYRAMID | THE INQUISITIVE





LOGIC PYRAMID

LEVEL:Beginner

Description

Identify the logic behind the series
6 28 66 120 190 276....
The numbers in the series should be used to create a Pyramid. The base of the Pyramid will be the widest and will start converging towards the top where there will only be one element. Each successive layer will have one number less than that on the layer below it. The width of the Pyramid is specified by an input parameter N. In other words there will be N numbers on the bottom layer of the pyramid.
The Pyramid construction rules are as follows
1. First number in the series should be at the top of the Pyramid
2. Last N number of the series should be on the bottom-most layer of the Pyramid, with Nth number being the right-most number of this layer.
3. Numbers less than 5-digits must be padded with zeroes to maintain the sanctity of a Pyramid when printed. Have a look at the examples below to get a pictorial understanding of what this rule actually means.

Input Format

First line of input will contain number N that corresponds to the width of the bottom-most layer of the Pyramid
Constraints:
0 < N <= 14

Output Format

The Pyramid constructed out of numbers in the series as per stated construction rules


Example 1:

Input
2
Output
 00006
00028 00066

Example 2:

Input
3
Output
  00006
 00028 00066
00120 00190 00276
Example 3:

Input
1
Output
00006

oops

Login to see Discussion




Approach

The logic behind the series generation is, the initial series value is 6, and the subseries value is 6, for the next series value, add 16 to subseries value and then add the subseries to the series value, continue this value til the nth count.


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution