title: Dynamic Programming Set 36 Cut A Rope To Maximize Product 1
signature: func dynamicProgrammingSet36CutARopeToMaximizeProduct1(n int) int64 {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int64, expected int64) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(n int, expected int64) 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(62, 6973568802)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver(53, 258280326)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver(8, 18)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver(6, 9)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver(35, 354294)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver(35, 354294)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver(46, 19131876)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver(74, 564859072962)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver(69, 94143178827)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver(3, 2)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
source_py: def dynamic_programming_set_36_cut_a_rope_to_maximize_product_1(n):
      if ((n == 2) or (n == 3)):
          return (n - 1)
      res = 1
      while (n > 4):
          n -= 3
          res *= 3
      return (n * res)
source_cpp: int dynamic_programming_set_36_cut_a_rope_to_maximize_product_1(int n) {
    if ( n == 2 || n == 3 ) return ( n - 1 );
    int res = 1;
    while ( n > 4 ) {
      n -= 3;
      res *= 3;
    }
    return ( n * res );
  }