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.
- Length of the longest ZigZag subarray of the given array
- 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
- Alternating Numbers
- Minimum number of given operations required to convert a permutation into an identity permutation
- Minimum number of adjacent swaps required to convert a permutation to another permutation by given condition
- Euler's Totient Function
- Euler's criterion (Check if square root under modulo p exists)
- Optimized Euler Totient Function for Multiple Evaluations
- Euler Method for solving differential equation
- Euler's Four Square Identity
- Euclid Euler Theorem
- Total nodes traversed in Euler Tour Tree
- Predictor-Corrector or Modified-Euler method for solving Differential equation
- Count integers in a range which are divisible by their euler totient value
- Check if a number is Euler Pseudoprime
- Euler's Factorization method
- Count of elements having Euler's Totient value one less than itself
- Probability of Euler's Totient Function in a range [L, R] to be divisible by M
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.