title: Friends Pairing Problem 2
signature: friends_pairing_problem_2 <- function(n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          24L, 
          17492190577600L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          1L, 
          1L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          29L, 
          101990226254706560L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          3L, 
          4L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          14L, 
          2390480L
      )))
  
  }
  
  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;
  }