title: Count Pairs Whose Products Exist In Array 1
signature: function count_pairs_whose_products_exist_in_array_1(arr, n)
source_py: def count_pairs_whose_products_exist_in_array_1(arr, n):
      result = 0
      Hash = set()
      for i in range(n):
          Hash.add(arr[i])
      for i in range(n):
          for j in range((i + 1), n):
              product = (arr[i] * arr[j])
              if (product in Hash):
                  result += 1
      return result
source_cpp: int count_pairs_whose_products_exist_in_array_1(vector<int> arr, int n) {
    int result = 0;
    set < int > Hash;
    for ( int i = 0;
    i < n;
    i ++ ) Hash . insert ( arr [ i ] );
    for ( int i = 0;
    i < n;
    i ++ ) {
      for ( int j = i + 1;
      j < n;
      j ++ ) {
        int product = arr [ i ] * arr [ j ];
        if ( Hash . find ( product ) != Hash . end ( ) ) result ++;
      }
    }
    return result;
  }
question_info.entry_fn_name: count_pairs_whose_products_exist_in_array_1
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
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(arr, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, 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({7, 10, 17, 17, 18, 20, 27, 28, 29, 29, 31, 32, 41, 43, 45, 46, 63, 66, 69, 69, 70, 75, 87, 95}, 17, 0)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-60}, 0, 0)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 9, 36)
      print(string.format("TEST-2...%s",result))
  
      result = driver({52, 83, 36, 57, 93, 11, 32, 91, 52}, 8, 0)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-98, -94, -90, -88, -76, -76, -64, -62, -60, -50, -46, -32, -24, -22, -20, -16, -4, -2, 6, 10, 20, 28, 30, 32, 34, 38, 40, 42, 54, 64, 72, 76, 82, 82, 86, 92, 92, 98, 98}, 22, 2)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0}, 42, 861)
      print(string.format("TEST-5...%s",result))
  
      result = driver({2, 3, 10, 12, 15, 23, 26, 28, 29, 30, 31, 31, 33, 33, 35, 41, 45, 48, 50, 50, 53, 53, 56, 65, 66, 67, 68, 68, 72, 72, 75, 76, 79, 82, 90, 94, 94, 95, 97, 99}, 35, 9)
      print(string.format("TEST-6...%s",result))
  
      result = driver({14, 36, -54, -54}, 3, 0)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1}, 12, 66)
      print(string.format("TEST-8...%s",result))
  
      result = driver({5, 69, 37, 80, 21, 98, 70, 70, 74, 95, 6, 67, 44, 55, 52, 89, 84, 99, 65, 52}, 12, 0)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"arr": [7, 10, 17, 17, 18, 20, 27, 28, 29, 29, 31, 32, 41, 43, 45, 46, 63, 66, 69, 69, 70, 75, 87, 95], "n": 17}}, {"idx": 1, "outputs": 0, "inputs": {"arr": [-60], "n": 0}}, {"idx": 2, "outputs": 36, "inputs": {"arr": [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 9}}, {"idx": 3, "outputs": 0, "inputs": {"arr": [52, 83, 36, 57, 93, 11, 32, 91, 52], "n": 8}}, {"idx": 4, "outputs": 2, "inputs": {"arr": [-98, -94, -90, -88, -76, -76, -64, -62, -60, -50, -46, -32, -24, -22, -20, -16, -4, -2, 6, 10, 20, 28, 30, 32, 34, 38, 40, 42, 54, 64, 72, 76, 82, 82, 86, 92, 92, 98, 98], "n": 22}}, {"idx": 5, "outputs": 861, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0], "n": 42}}, {"idx": 6, "outputs": 9, "inputs": {"arr": [2, 3, 10, 12, 15, 23, 26, 28, 29, 30, 31, 31, 33, 33, 35, 41, 45, 48, 50, 50, 53, 53, 56, 65, 66, 67, 68, 68, 72, 72, 75, 76, 79, 82, 90, 94, 94, 95, 97, 99], "n": 35}}, {"idx": 7, "outputs": 0, "inputs": {"arr": [14, 36, -54, -54], "n": 3}}, {"idx": 8, "outputs": 66, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1], "n": 12}}, {"idx": 9, "outputs": 0, "inputs": {"arr": [5, 69, 37, 80, 21, 98, 70, 70, 74, 95, 6, 67, 44, 55, 52, 89, 84, 99, 65, 52], "n": 12}}]