title: Sum Of All Proper Divisors Of A Natural Number
signature: func sumOfAllProperDivisorsOfANaturalNumber(num int) float64 {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual float64, expected float64) bool {
      return math.Abs(actual - expected) < 1e-06
  }
  
  func driver(num int, expected float64) string {
      if validateSolution(PLACEHOLDER_FN_NAME(num),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver(2, 1.0)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver(57, 23.0)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver(28, 28.0)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver(43, 1.0)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver(38, 22.0)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver(29, 1.0)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver(45, 33.0)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver(47, 1.0)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver(44, 40.0)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver(3, 1.0)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
source_py: def sum_of_all_proper_divisors_of_a_natural_number(num):
      result = 0
      i = 2
      while (i <= math.sqrt(num)):
          if ((num % i) == 0):
              if (i == (num / i)):
                  result = (result + i)
              else:
                  result = (result + (i + (num / i)))
          i = (i + 1)
      return (result + 1)
source_cpp: int sum_of_all_proper_divisors_of_a_natural_number(int num) {
    int result = 0;
    for ( int i = 2;
    i <= sqrt ( num );
    i ++ ) {
      if ( num % i == 0 ) {
        if ( i == ( num / i ) ) result += i;
        else result += ( i + num / i );
      }
    }
    return ( result + 1 );
  }