title: Count Total Set Bits In All Numbers From 1 To N
signature: class Solution {
  
      public Integer countTotalSetBitsInAllNumbersFrom1ToN(Integer n) {
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.extension: java
question_info.entry_fn_name: countTotalSetBitsInAllNumbersFrom1ToN
question_info.entry_cls_name: Solution
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.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(Integer n, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(n,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(90, 279);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(56, 159);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(43, 112);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(31, 80);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(77, 231);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(35, 88);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(43, 112);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(66, 197);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(15, 32);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(95, 304);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(Integer n, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(n),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__