Baum Sweet Sequence is an infinite binary sequence of 0s and 1s. The nth term of the sequence is 1 if the number n has no odd number of contiguous zeroes in its binary representation, else the nth term is 0.
The first few terms of the sequence are: b1 = 1 (binary of 1 is 1) b2 = 0 (binary of 2 is 10) b3 = 1 (binary of 3 is 11) b4 = 1 (binary of 4 is 100) b5 = 0 (binary of 5 is 101) b6 = 0 (binary of 6 is 110)
Given a natural number n. The task is to find the nth term of the Baum Sweet sequence, i.e, check whether it contains any consecutive block of zeroes of odd length.
Input: n = 8 Output: 0 Explanations: Binary representation of 8 is 1000. It contains odd length block of consecutive 0s. Therefore B8 is 0. Input: n = 5 Output: 1 Input: n = 7 Output: 0
The idea is to run a loop through the binary representation of n and count the length of all the consecutive zero blocks present. If there is at-least one odd length zero block, then the nth term for the given input n is 0 else it is 1.
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.
- Sum of the sequence 2, 22, 222, .........
- Gould's Sequence
- Gijswijt's Sequence
- Alcuin's Sequence
- Connell Sequence
- Aronson's Sequence
- Find F(n) when F(i) and F(j) of a sequence are given
- Sylvester's sequence
- Farey Sequence
- Aliquot Sequence
- Increasing sequence with given GCD
- Recaman's sequence
- k-th number in the Odd-Even sequence
- Juggler Sequence
- Padovan Sequence
- Beatty sequence
- Sum of numbers from 1 to N which are in Lucas Sequence
- Euclid–Mullin Sequence
- Sum of first N terms of Quadratic Sequence 3 + 7 + 13 + ...
- Program to find sum of the given 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 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.
Improved By : gowtham_yuvaraj