# Very Cool Number | Coolness of Binary Equivalent | Solution

```2
102 1
21 2
```

```48
1
```

#### Solution: We strongly recommend you to try the problem first before moving to the solution. C++ (STL)

```/* C++ code for Very Cool number */
/* www.codewindow.in */

#include <bits/stdc++.h>
using namespace std;

// Function for converting decimal to binary and return as string
string dec_to_binary(int n) {
string s;
for(int i=15; i>=0; --i) {  // Supposing sizeof integer as 16 bits
int temp=n>>i;
if(temp & 1)
s+='1';
else
s+='0';
}
return s;
}

// Solution Function
void solve() {
int n, k, r, ans=0, cool;
cin >> r >> k;
for(int num=1; num<=r; ++num) {
cool=0;
string s=dec_to_binary(num);
for(int i=0; i<s.length(); ++i) {
string temp=s.substr(i, 3);  // Substring of size 3 starting from i
if(temp=="101")
++cool;
}
if(cool>=k)  // If (coolness>=k) then count it
++ans;
}
cout << ans << "\n";
}

// Driver code
int main() {
ios::sync_with_stdio(0);
cin.tie(0);

int t=1;
cin >> t;   // Input the testcases
while(t--)
solve();

return 0;
}
```

```2
102 1
21 2
```

```48
1
```