Given a number n. The task is to print the Aikten’s array upto n.
Input: 5 Output:  [1, 2] [2, 3, 5] [5, 7, 10, 15] [15, 20, 27, 37, 52] Input: 7 Output:  [1, 2] [2, 3, 5] [5, 7, 10, 15] [15, 20, 27, 37, 52] [52, 67, 87, 114, 151, 203] [203, 255, 322, 409, 523, 674, 877]
To print it first we follow the following steps:
- We write 1 in the first row.
- Next, we fill the leftmost value of each row by the rightmost value of the previous row.
- The next elements of each row are filled by the simple rule i.e. each element of a particular row is the sum of values to the left of that row with the values of the upper row at the same position.
For better understanding, let’s consider the third row of the above example consisting of the elements 2, 3, 5. The leftmost value of this row is the rightmost value of the above row i.e. 2. The next value 3 is the sum of value to the left if that row (2) and the value at same position of the above row (1). Similarly, 5 is the sum of 3 and 2.
Below is the implementation.
 [1, 2] [2, 3, 5] [5, 7, 10, 15] [15, 20, 27, 37, 52] [52, 67, 87, 114, 151, 203] [203, 255, 322, 409, 523, 674, 877]
- Program to print all distinct elements of a given integer array in Python | Ordered Dictionary
- Python Program for Efficient program to print all prime factors of a given number
- Python Program for Program to Print Matrix in Z form
- Python program to print Emojis
- Program to print product of even and odd indexed elements in an Array
- Python Program to Print Numbers in an Interval
- Python program to print calendar of given year
- Python Program to print digit pattern
- Python program to print all even numbers in a range
- Python program to print all odd numbers in a range
- Python Program to print all permutations of a given string
- Python program to print odd numbers in a List
- Python program to print even numbers in a list
- Python program to print all negative numbers in a range
- Python | Program to print duplicates from a list of integers
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.