<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 {
public:
    long long func(long long n) {

        vector<long long> dp(33, 0);
        for(int i = 2; i<33; i++)
        {
            dp[i] = (1LL<<(i-2)) + dp[i-1] + dp[i-2];
        }
        // for(auto it: dp)
        // {
        //     cout<<it<<" ";
        // }
        // cout<<"\n";
        long long num = 1;
        long long ind = 0;
        // cout<<n<<" n\n";
        while(num-1 < n)
        {
            num*= 2;
            ind++;
        }
        if(num - 1 == n)
        {
            // cout<<n+1 - dp[ind]<<" <--returned\n";
            return dp[ind];
        }
        long long ans = dp[ind-1];
        // cout<<ans<<" ans\n";
        long long temp = (3*num)/4;
        // cout<<temp<<" temp\n";

        if(n < temp)
        {
            return ans += func(n - num/2);
        }
        else
        {
            ans += (n-temp+1);
            // cout<<ans<<" <--\n";
            return ans + func(temp-1 - num/2);
        } 
    }


    int findIntegers(int n)
    {
        return n+1 - func(n);
    }
};
8800