Advertisement
alexgor1998

Leetcode 1680

Sep 23rd, 2022
1,176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     int concatenatedBinary(int n) {
  4.  
  5.         unsigned long long val = 0;
  6.         int big_prime = 1e9 + 7;
  7.         int bin_power = 1;
  8.         int bin_digits = 0;
  9.  
  10.         for(int i = 1; i <= n; ++i){
  11.             if(i > (bin_power-1)){
  12.                 bin_power = bin_power << 1;
  13.                 bin_digits++;
  14.             }
  15.             val = ((val << bin_digits) + i) % big_prime;
  16.         }
  17.     return val;
  18.     }
  19. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement