<p>Given a positive integer <code>n</code>, return the number of the integers in the range <code>[0, n]</code> whose binary representations <strong>do not</strong> contain consecutive ones.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> n = 5
<strong>Output:</strong> 5
<strong>Explanation:</strong>
Here are the non-negative integers &lt;= 5 with their corresponding binary representations:
0 : 0
1 : 1
2 : 10
3 : 11
4 : 100
5 : 101
Among them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule. 
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> 2
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> n = 2
<strong>Output:</strong> 3
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    def findIntegers(self, n: int) -> int:
        return self.fun2(n)

    def fun2(self, n):
        if n == 0:
            return 1
        if n == 1:
            return 2
        if n == 2:
            return 3

        nb = bin(n)[2:]

        k = len(nb)
        dp = [0] * (k + 1)
        dp[0] = 1
        dp[1] = 2
        dp[2] = 3
        n1 = 1
        n2 = 0
        for i in range(3, k + 1):
            n1, n2 = n1 + n2, n1
            dp[i] = dp[i - 1] + n1 + n2

        if "0" not in nb:
            return dp[k]

        res = 0
        for i in range(k - 1):
            if nb[i] == "1":
                if nb[i + 1] == "0":
                    res += dp[k - i - 1]
                else:
                    res += 2 * dp[k - i - 2]
                    if k - i - 2 > 0:
                        res += dp[k - i - 3]
                    else:
                        res += 1
                    break

        if "11" not in nb:
            if nb[-1] == "1":
                res += 2
            else:
                res += 1

        return res

    def fun1(self, n: int) -> int:

        if n == 0:
            return 1
        if n == 1:
            return 2
        if n == 2:
            return 3

        buf = []
        res = 2
        k = 2
        while k <= n:
            res += 1
            buf.append(2 * k)
            if k % 2 == 0:
                buf.append(2 * k + 1)
            k = buf.pop(0)

        return res


16500