title: Sum Largest Prime Factor Number Less Equal N
signature: int sumLargestPrimeFactorNumberLessEqualN(int n) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual == expected;
  }
  
  string driver(int n, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver(6, 15); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver(35, 291); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver(87, 1554); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver(91, 1672); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver(63, 875); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver(11, 43); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver(66, 901); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver(17, 90); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver(92, 1695); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver(81, 1334); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
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;
  }