title: Sum Largest Prime Factor Number Less Equal N
signature: func sumLargestPrimeFactorNumberLessEqualN(n int) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(n int, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(n),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver(6, 15)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver(35, 291)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver(87, 1554)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver(91, 1672)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver(63, 875)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver(11, 43)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver(66, 901)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver(17, 90)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver(92, 1695)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver(81, 1334)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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;
  }