title: Number Of Pairs In An Array Having Sum Equal To Product
signature: function number_of_pairs_in_an_array_having_sum_equal_to_product(a, n)
source_py: def number_of_pairs_in_an_array_having_sum_equal_to_product(a, n):
      zero = 0
      two = 0
      for i in range(n):
          if (a[i] == 0):
              zero += 1
          if (a[i] == 2):
              two += 1
      cnt = (((zero * (zero - 1)) // 2) + ((two * (two - 1)) // 2))
      return cnt
source_cpp: int number_of_pairs_in_an_array_having_sum_equal_to_product(vector<int> a, int n) {
    int zero = 0, two = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( a [ i ] == 0 ) {
        zero ++;
      }
      if ( a [ i ] == 2 ) {
        two ++;
      }
    }
    int cnt = ( zero * ( zero - 1 ) ) / 2 + ( two * ( two - 1 ) ) / 2;
    return cnt;
  }
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(a, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(a, n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({9, 10, 20, 26, 26, 28, 31, 34, 35, 36, 36, 37, 39, 43, 44, 44, 46, 49, 54, 57, 58, 63, 64, 64, 65, 67, 70, 70, 74, 75, 77, 78, 79, 81, 82, 83, 84, 86, 95}, 31, 0)
      print(string.format("TEST-0...%s",result))
  
      result = driver({0, -10, 10, 0, 68, 4, -6, -14, 74, -80, 56, -4, 36, 56, 10, -16, 90, 84, -38, -40, 40, -86, -36, -16, -48, -76, -72, -18, -14, -40, -82, 56, -60}, 19, 1)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 22, 21)
      print(string.format("TEST-2...%s",result))
  
      result = driver({88, 20, 53, 21, 29, 73, 62, 91, 72, 34, 47, 42, 98, 9, 79, 80, 94, 36, 7, 67, 96, 34, 99, 56, 37, 70, 55, 36, 10, 77, 41, 51, 5, 37, 57, 29, 56, 74, 97, 31, 96, 52, 13, 29, 87, 58, 28, 31}, 38, 0)
      print(string.format("TEST-3...%s",result))
  
      result = driver({20}, 0, 0)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1}, 21, 15)
      print(string.format("TEST-5...%s",result))
  
      result = driver({2, 4, 9, 16, 22, 23, 25, 33, 33, 36, 39, 48, 49, 52, 53, 60, 67, 68, 76, 77, 79, 84, 84, 86, 89}, 24, 0)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-62, 42, -88, -44, 90, 30, 52, 54, 56, -72, -76, 90, 18, 42, 62, -84, 56, -80, 72}, 13, 0)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 15, 15)
      print(string.format("TEST-8...%s",result))
  
      result = driver({22, 15, 28, 29, 32, 16, 33, 83}, 7, 0)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"a": [9, 10, 20, 26, 26, 28, 31, 34, 35, 36, 36, 37, 39, 43, 44, 44, 46, 49, 54, 57, 58, 63, 64, 64, 65, 67, 70, 70, 74, 75, 77, 78, 79, 81, 82, 83, 84, 86, 95], "n": 31}}, {"idx": 1, "outputs": 1, "inputs": {"a": [0, -10, 10, 0, 68, 4, -6, -14, 74, -80, 56, -4, 36, 56, 10, -16, 90, 84, -38, -40, 40, -86, -36, -16, -48, -76, -72, -18, -14, -40, -82, 56, -60], "n": 19}}, {"idx": 2, "outputs": 21, "inputs": {"a": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 22}}, {"idx": 3, "outputs": 0, "inputs": {"a": [88, 20, 53, 21, 29, 73, 62, 91, 72, 34, 47, 42, 98, 9, 79, 80, 94, 36, 7, 67, 96, 34, 99, 56, 37, 70, 55, 36, 10, 77, 41, 51, 5, 37, 57, 29, 56, 74, 97, 31, 96, 52, 13, 29, 87, 58, 28, 31], "n": 38}}, {"idx": 4, "outputs": 0, "inputs": {"a": [20], "n": 0}}, {"idx": 5, "outputs": 15, "inputs": {"a": [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1], "n": 21}}, {"idx": 6, "outputs": 0, "inputs": {"a": [2, 4, 9, 16, 22, 23, 25, 33, 33, 36, 39, 48, 49, 52, 53, 60, 67, 68, 76, 77, 79, 84, 84, 86, 89], "n": 24}}, {"idx": 7, "outputs": 0, "inputs": {"a": [-62, 42, -88, -44, 90, 30, 52, 54, 56, -72, -76, 90, 18, 42, 62, -84, 56, -80, 72], "n": 13}}, {"idx": 8, "outputs": 15, "inputs": {"a": [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 15}}, {"idx": 9, "outputs": 0, "inputs": {"a": [22, 15, 28, 29, 32, 16, 33, 83], "n": 7}}]
question_info.extension: lua
question_info.entry_fn_name: number_of_pairs_in_an_array_having_sum_equal_to_product
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__