title: Friends Pairing Problem 2
signature: fun friendsPairingProblem2(n: Int): Long {
test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Long, expected:Long):Boolean{
    return actual.equals(expected)
  }
  fun driver(n: Int, expected:Long):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(n), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver(24, 17492190577600)
      println("TEST-0...${result}")
      
      result = driver(1, 1)
      println("TEST-1...${result}")
      
      result = driver(29, 101990226254706560)
      println("TEST-2...${result}")
      
      result = driver(3, 4)
      println("TEST-3...${result}")
      
      result = driver(14, 2390480)
      println("TEST-4...${result}")
      
          
  }
  
  main()
source_py: def friends_pairing_problem_2(n):
      (a, b, c) = (1, 2, 0)
      if (n <= 2):
          return n
      for i in range(3, (n + 1)):
          c = (b + ((i - 1) * a))
          a = b
          b = c
      return c
source_cpp: int friends_pairing_problem_2(int n) {
    int a = 1, b = 2, c = 0;
    if ( n <= 2 ) {
      return n;
    }
    for ( int i = 3;
    i <= n;
    i ++ ) {
      c = b + ( i - 1 ) * a;
      a = b;
      b = c;
    }
    return c;
  }