title: Sum Pairwise Products 1
signature: func sumPairwiseProducts1(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(41, 382571)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver(50, 834275)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver(67, 2645897)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver(18, 15675)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver(60, 1711355)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver(6, 266)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver(27, 74907)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver(46, 601036)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver(50, 834275)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver(20, 23485)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
source_py: def sum_pairwise_products_1(n):
      multiTerms = ((n * (n + 1)) // 2)
      sm = multiTerms
      for i in range(2, (n + 1)):
          multiTerms = (multiTerms - (i - 1))
          sm = (sm + (multiTerms * i))
      return sm
source_cpp: long long int sum_pairwise_products_1(int n) {
    long long int multiTerms = n * ( n + 1 ) / 2;
    long long int sum = multiTerms;
    for ( int i = 2;
    i <= n;
    i ++ ) {
      multiTerms = multiTerms - ( i - 1 );
      sum = sum + multiTerms * i;
    }
    return sum;
  }