title: Sum Largest Prime Factor Number Less Equal N
signature: class Solution {
  
      public Integer sumLargestPrimeFactorNumberLessEqualN(Integer n) {
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(6, 15);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(35, 291);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(87, 1554);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(91, 1672);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(63, 875);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(11, 43);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(66, 901);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(17, 90);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(92, 1695);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(81, 1334);
          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
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;
  }