title: Number Of Pairs In An Array Having Sum Equal To Product
signature: number_of_pairs_in_an_array_having_sum_equal_to_product <- function(a, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(a, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(a, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(9L, 10L, 20L, 26L, 26L, 28L, 31L, 34L, 35L, 36L, 36L, 37L, 39L, 43L, 44L, 44L, 46L, 49L, 54L, 57L, 58L, 63L, 64L, 64L, 65L, 67L, 70L, 70L, 74L, 75L, 77L, 78L, 79L, 81L, 82L, 83L, 84L, 86L, 95L), 31L, 
          0L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(0L, -10L, 10L, 0L, 68L, 4L, -6L, -14L, 74L, -80L, 56L, -4L, 36L, 56L, 10L, -16L, 90L, 84L, -38L, -40L, 40L, -86L, -36L, -16L, -48L, -76L, -72L, -18L, -14L, -40L, -82L, 56L, -60L), 19L, 
          1L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 22L, 
          21L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(88L, 20L, 53L, 21L, 29L, 73L, 62L, 91L, 72L, 34L, 47L, 42L, 98L, 9L, 79L, 80L, 94L, 36L, 7L, 67L, 96L, 34L, 99L, 56L, 37L, 70L, 55L, 36L, 10L, 77L, 41L, 51L, 5L, 37L, 57L, 29L, 56L, 74L, 97L, 31L, 96L, 52L, 13L, 29L, 87L, 58L, 28L, 31L), 38L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(20L), 0L, 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L), 21L, 
          15L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(2L, 4L, 9L, 16L, 22L, 23L, 25L, 33L, 33L, 36L, 39L, 48L, 49L, 52L, 53L, 60L, 67L, 68L, 76L, 77L, 79L, 84L, 84L, 86L, 89L), 24L, 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(-62L, 42L, -88L, -44L, 90L, 30L, 52L, 54L, 56L, -72L, -76L, 90L, 18L, 42L, 62L, -84L, 56L, -80L, 72L), 13L, 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 15L, 
          15L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(22L, 15L, 28L, 29L, 32L, 16L, 33L, 83L), 7L, 
          0L
      )))
  
  }
  
  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;
  }