title: Friends Pairing Problem 2
signature: function friendsPairingProblem2(n) {
test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value) {
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual, expected){
      return convertToString(actual)===convertToString(expected);
  }
  
  function driver(n, expected){
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(n),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver(24, 17492190577600);
    console.log(`TEST-0...${result}`);
  
    result = driver(1, 1);
    console.log(`TEST-1...${result}`);
  
    result = driver(29, 101990226254706560);
    console.log(`TEST-2...${result}`);
  
    result = driver(3, 4);
    console.log(`TEST-3...${result}`);
  
    result = driver(14, 2390480);
    console.log(`TEST-4...${result}`);
  
    process.exit(0);
  };
  
  if (require.main === module) {
    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;
  }