Given an integer ‘n’, generate the first ‘n’ terms of the Connell Sequence.
Connell Sequence is the sequence formed with the first odd number, i.e 1 as its first term. The subsequent terms of the sequence are made up of the first two even numbers, i.e 2 and 4, followed by the next three odd numbers, i.e 5, 7 and 9, followed by the next four even numbers, i.e 10, 12, 14 and 16 and so on …. the sequence continues.
Input : 6 Output : 1 2 4 5 7 9 Input : 12 Output : 1 2 4 5 7 9 10 12 14 16 17 19
It may be noted here that writing the terms in new lines as, first term in first line, next two terms in next line, next three terms in next line and so on, gives an interesting pattern as:
Line 1 : 1
Line 2 : 2 4
Line 3 : 5 7 9
Line 4 : 10 12 14 16
Line 5 : 17 19 21 23 25
and so on…
The pattern is every last number of a particular line is equal to that line number squared.
- In line 2 last number is 4 which is equal to its line number squared, i.e 2^2
- In line 5 last number is 25 which is equal to its line number squared, i.e 5^2
Below is a simple implementation where we generate result by alternatively adding odd and even number of elements. We use size of current list to decide next number of elements to push.
The first 10 terms are 1 2 4 5 7 9 10 12 14 16
- Sum of the sequence 2, 22, 222, .........
- Look-and-Say Sequence
- Gould's Sequence
- Gijswijt's Sequence
- Alcuin's Sequence
- Golomb sequence
- Increasing sequence with given GCD
- Sylvester's sequence
- k-th number in the Odd-Even sequence
- Aronson's Sequence
- Farey Sequence
- Find F(n) when F(i) and F(j) of a sequence are given
- Aliquot Sequence
- Padovan Sequence
- Juggler Sequence
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.