Simple Recursive 1 line C++ & Python solution
The idea is to use a simple formula:\na(n) = a(n-1) * 2^(1 + floor(log2(n))) + n\nC++: \n\nclass Solution {\npublic:\n    const int mod = 1e9 + 7;\n    int conc
The idea is to use a simple formula:\n**a(n) = a(n-1) * 2^(1 + floor(log2(n))) + n**\n**C++:** \n```\nclass Solution {\npublic:\n    const int mod = 1e9 + 7;\n    int concatenatedBinary(int n) {\n        return (n == 1) ? 1 : (concatenatedBinary(n - 1) * (long)(pow(2, 1 + (int)log2(n))) + n) % mod;\n    }\n};\n```\n**PS:** The declaration line of mod can be removed and it can be directly placed in the return statement of the function.\n\n**Python:**\n```\nclass Solution:\n    def concatenatedBinary(self, n: int) -> int:\n        return 1 if n == 1 else (self.concatenatedBinary(n - 1) * int(math.pow(2, 1 + int(math.log2(n)))) + n) % (10 ** 9 + 7)\n```
['C', 'Python']