title: Number Of Pairs In An Array Having Sum Equal To Product
signature: function numberOfPairsInAnArrayHavingSumEqualToProduct($a, $n) {
test_code: <?php
  
  
  // SOLUTION CODE 
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function validateSolution($actual, $expected){
      return serialize($actual) == serialize($expected);
  }
  
  function driver($a, $n, $expected){
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME($a, $n), $expected)){
          return "PASSED";
        }
        return "FAILED";
      }
      catch (Exception $exception_obj) {
        return get_class($exception_obj);
      }
  }
  
  function main(){
      printf("TEST-0...%s\n",driver(
        array(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));
      
      printf("TEST-1...%s\n",driver(
        array(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));
      
      printf("TEST-2...%s\n",driver(
        array(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));
      
      printf("TEST-3...%s\n",driver(
        array(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));
      
      printf("TEST-4...%s\n",driver(
        array(20), 0, 
        0));
      
      printf("TEST-5...%s\n",driver(
        array(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));
      
      printf("TEST-6...%s\n",driver(
        array(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));
      
      printf("TEST-7...%s\n",driver(
        array(-62, 42, -88, -44, 90, 30, 52, 54, 56, -72, -76, 90, 18, 42, 62, -84, 56, -80, 72), 13, 
        0));
      
      printf("TEST-8...%s\n",driver(
        array(0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), 15, 
        15));
      
      printf("TEST-9...%s\n",driver(
        array(22, 15, 28, 29, 32, 16, 33, 83), 7, 
        0));
      
  }
  
  main();
  ?>
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;
  }