title: Sum Largest Prime Factor Number Less Equal N
signature: function sumLargestPrimeFactorNumberLessEqualN(n: number): number {
source_py: def sum_largest_prime_factor_number_less_equal_n(n):
      prime = ([0] * (n + 1))
      sum = 0
      max = int((n / 2))
      for p in range(2, (max + 1)):
          if (prime[p] == 0):
              for i in range((p * 2), (n + 1), p):
                  prime[i] = p
      for p in range(2, (n + 1)):
          if prime[p]:
              sum += prime[p]
          else:
              sum += p
      return sum
source_cpp: int sum_largest_prime_factor_number_less_equal_n(int n) {
    int prime [ n + 1 ], sum = 0;
    memset ( prime, 0, sizeof ( prime ) );
    int max = n / 2;
    for ( int p = 2;
    p <= max;
    p ++ ) {
      if ( prime [ p ] == 0 ) {
        for ( int i = p * 2;
        i <= n;
        i += p ) prime [ i ] = p;
      }
    }
    for ( int p = 2;
    p <= n;
    p ++ ) {
      if ( prime [ p ] ) sum += prime [ p ];
      else sum += p;
    }
    return sum;
  }
question_info.test_list: [{"idx": 0, "outputs": 15, "inputs": {"n": 6}}, {"idx": 1, "outputs": 291, "inputs": {"n": 35}}, {"idx": 2, "outputs": 1554, "inputs": {"n": 87}}, {"idx": 3, "outputs": 1672, "inputs": {"n": 91}}, {"idx": 4, "outputs": 875, "inputs": {"n": 63}}, {"idx": 5, "outputs": 43, "inputs": {"n": 11}}, {"idx": 6, "outputs": 901, "inputs": {"n": 66}}, {"idx": 7, "outputs": 90, "inputs": {"n": 17}}, {"idx": 8, "outputs": 1695, "inputs": {"n": 92}}, {"idx": 9, "outputs": 1334, "inputs": {"n": 81}}]
question_info.entry_cls_name: Solution
question_info.test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return convertToString(actual) === convertToString(expected);
  }
  
  function driver(n: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(n),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver(6, 15);
    console.log(`TEST-0...${result}`);
  
    result = driver(35, 291);
    console.log(`TEST-1...${result}`);
  
    result = driver(87, 1554);
    console.log(`TEST-2...${result}`);
  
    result = driver(91, 1672);
    console.log(`TEST-3...${result}`);
  
    result = driver(63, 875);
    console.log(`TEST-4...${result}`);
  
    result = driver(11, 43);
    console.log(`TEST-5...${result}`);
  
    result = driver(66, 901);
    console.log(`TEST-6...${result}`);
  
    result = driver(17, 90);
    console.log(`TEST-7...${result}`);
  
    result = driver(92, 1695);
    console.log(`TEST-8...${result}`);
  
    result = driver(81, 1334);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: sumLargestPrimeFactorNumberLessEqualN
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: tsc --target es2020 --lib es5,dom,es2015,es2020 __FILENAME__
question_info.commands: node __FILENAME__.js