class Solution {
string binary(int n,string &s){
if(n<=0) return s;
binary(n--,s);
while(n){
if(n & 1) s += '1';
else s+= '0';
n--;
}
return s;
}
public:
long long int concatenatedBinary(int n) {
string s,temp;
int k=0,m = 1000000007;
temp = binary(n,s);
reverse(temp.begin(),temp.end());
k = stoll(temp,nullptr,10);
return k%m;
it's a leetcode problem no 1680. Concatenation of Consecutive Binary Numbers