title: Count Total Set Bits In All Numbers From 1 To N
signature: fun countTotalSetBitsInAllNumbersFrom1ToN(n: Int): Int {
source_py: def count_total_set_bits_in_all_numbers_from_1_to_n(n):
      i = 0
      ans = 0
      while ((1 << i) <= n):
          k = 0
          change = (1 << i)
          for j in range(0, (n + 1)):
              ans += k
              if (change == 1):
                  k = (not k)
                  change = (1 << i)
              else:
                  change -= 1
          i += 1
      return ans
source_cpp: int count_total_set_bits_in_all_numbers_from_1_to_n(int n) {
    int i = 0;
    int ans = 0;
    while ( ( 1 << i ) <= n ) {
      bool k = 0;
      int change = 1 << i;
      for ( int j = 0;
      j <= n;
      j ++ ) {
        ans += k;
        if ( change == 1 ) {
          k = ! k;
          change = 1 << i;
        }
        else {
          change --;
        }
      }
      i ++;
    }
    return ans;
  }
question_info.test_list: [{"idx": 0, "outputs": 279, "inputs": {"n": 90}}, {"idx": 1, "outputs": 159, "inputs": {"n": 56}}, {"idx": 2, "outputs": 112, "inputs": {"n": 43}}, {"idx": 3, "outputs": 80, "inputs": {"n": 31}}, {"idx": 4, "outputs": 231, "inputs": {"n": 77}}, {"idx": 5, "outputs": 88, "inputs": {"n": 35}}, {"idx": 6, "outputs": 112, "inputs": {"n": 43}}, {"idx": 7, "outputs": 197, "inputs": {"n": 66}}, {"idx": 8, "outputs": 32, "inputs": {"n": 15}}, {"idx": 9, "outputs": 304, "inputs": {"n": 95}}]
question_info.extension: kts
question_info.test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Int, expected:Int):Boolean{
    return actual.equals(expected)
  }
  fun driver(n: Int, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(90, 279)
      println("TEST-0...${result}")
      
      result = driver(56, 159)
      println("TEST-1...${result}")
      
      result = driver(43, 112)
      println("TEST-2...${result}")
      
      result = driver(31, 80)
      println("TEST-3...${result}")
      
      result = driver(77, 231)
      println("TEST-4...${result}")
      
      result = driver(35, 88)
      println("TEST-5...${result}")
      
      result = driver(43, 112)
      println("TEST-6...${result}")
      
      result = driver(66, 197)
      println("TEST-7...${result}")
      
      result = driver(15, 32)
      println("TEST-8...${result}")
      
      result = driver(95, 304)
      println("TEST-9...${result}")
      
          
  }
  
  main()
question_info.entry_fn_name: countTotalSetBitsInAllNumbersFrom1ToN
question_info.entry_cls_name: Solution
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: kotlinc -script __FILENAME__ -no-reflect -nowarn