1680.cpp (317B)
1 class Solution { 2 static const int MOD = 1E9 + 7; 3 4 public: 5 int concatenatedBinary(int n) const { 6 long crnt = 0; 7 for (int i = 1, size = 0; i <= n; i++) { 8 if (__builtin_popcount(i) == 1) size++; 9 crnt = ((crnt << size) + i) % MOD; 10 } 11 return crnt; 12 } 13 };