Euler Zigzag numbers is a sequence of integers which is a number of arrangements of those numbers so that each entry is alternately greater or less than the preceding entry.
c1, c2, c3, c4 is Alternating permutation where
c1 < c2
c3 < c2
c3 < c4…
zigzag numbers are as follows 1, 1, 1, 2, 5, 16, 61, 272, 1385, 7936, 50521 ……
For a given integer N. The task is to print sequence up to N terms.
Input : N = 10
Output : 1 1 1 2 5 16 61 272 1385 7936
Input : N = 14
Output : 1 1 1 2 5 16 61 272 1385 7936 50521 353792 2702765 22368256
The (n+1)th Zigzag number is :
We will find the factorial upto n and store them in an array and also create a second array to store the i th zigzag number and apply the formula stated above to find all the n zigzag numbers.
Below is the implementation of the above approach :
zig zag numbers: 1 1 1 2 5 16 61 272 1385 7936
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Alternating Numbers
- Euler's Totient function for all numbers smaller than or equal to n
- Sum of alternating sign Squares of first N natural numbers
- Sum of alternating sign cubes of first N Natural numbers
- Check if an Array is a permutation of numbers from 1 to N
- Increasing permutation of first N natural numbers
- Check if an Array is a permutation of numbers from 1 to N : Set 2
- Find the K-th Permutation Sequence of first N natural numbers
- Find the permutation of first N natural numbers such that sum of i % Pi is maximum possible
- Find the good permutation of first N natural numbers
- Find a permutation of 2N numbers such that the result of given expression is exactly 2K
- Count of subarrays of size K which is a permutation of numbers from 1 to K
- Minimum steps to convert an Array into permutation of numbers from 1 to N
- Find permutation of first N natural numbers that satisfies the given condition
- Number of valid indices in the permutation of first N natural numbers
- Sort permutation of N natural numbers using triple cyclic right swaps
- Minimum cost to make an Array a permutation of first N natural numbers
- Find the number of sub arrays in the permutation of first N natural numbers such that their median is M
- Minimum number of adjacent swaps required to convert a permutation to another permutation by given condition
- Minimum number of given operations required to convert a permutation into an identity permutation
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.