C++ O(n) Solution
Left shift the answer every time by len and add the number, and then increment the length value at powers of 2.\n\n  int concatenatedBinary(int n) {\n    long a
Left shift the answer every time by len and add the number, and then increment the length value at powers of 2.\n```\n  int concatenatedBinary(int n) {\n    long ans=0;\n    int mod=1e9+7,len=1;\n    for(int i=1;i<=n;++i){\n        ans=(ans<<len)%mod+i;\n        if((i&(i+1))==0)\n            len++;\n    }\n\treturn ans % mod;\n  }\n```
['C', 'C++']