title: Count Pairs Whose Products Exist In Array
signature: count_pairs_whose_products_exist_in_array <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(3L, 7L, 26L, 40L, 46L, 89L, 99L), 5L, 
          0L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(98L, 42L, -24L, -60L, 74L, 86L, 6L, 8L, 72L, -58L, 38L, -20L, 6L, -6L, 8L, 48L, -34L, 30L, 60L, 66L, 38L, -54L, 8L, -94L, -8L, 0L, -64L, -94L, -94L, -72L, -84L, -36L, 88L, -62L, -88L, 46L, -4L, 88L), 24L, 
          6L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 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, 1L, 1L, 1L, 1L), 44L, 
          946L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(37L, 97L, 57L, 82L, 29L, 68L, 94L, 38L, 81L, 48L, 13L, 84L, 57L, 5L, 27L, 87L, 11L, 35L, 82L, 53L, 67L, 31L, 15L, 99L, 6L, 93L, 91L, 92L, 3L, 23L, 90L, 27L, 6L, 33L, 78L, 3L, 19L, 19L, 27L), 36L, 
          18L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-80L, -74L, -72L, -72L, -66L, -66L, -62L, -50L, -44L, -44L, -28L, -24L, -24L, -22L, -16L, -10L, -6L, -4L, -2L, 2L, 2L, 4L, 12L, 16L, 16L, 28L, 30L, 32L, 32L, 38L, 38L, 72L, 84L, 86L, 88L, 90L, 96L), 34L, 
          15L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L), 18L, 
          153L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(25L, 67L), 1L, 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(82L, 74L, -82L, 22L, -28L, -78L, -22L, -86L, -74L, 42L, -6L, 54L, -88L, -92L, -14L, -50L, 68L, 46L, -50L, 46L, -18L, 66L, -76L, -30L, 36L, 12L, 66L), 14L, 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 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, 1L, 1L), 32L, 
          496L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(50L, 23L, 56L, 9L), 3L, 
          0L
      )))
  
  }
  
  main()
source_py: def count_pairs_whose_products_exist_in_array(arr, n):
      result = 0
      for i in range(0, n):
          for j in range((i + 1), n):
              product = (arr[i] * arr[j])
              for k in range(0, n):
                  if (arr[k] == product):
                      result = (result + 1)
                      break
      return result
source_cpp: int count_pairs_whose_products_exist_in_array(vector<int> arr, int n) {
    int result = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      for ( int j = i + 1;
      j < n;
      j ++ ) {
        int product = arr [ i ] * arr [ j ];
        for ( int k = 0;
        k < n;
        k ++ ) {
          if ( arr [ k ] == product ) {
            result ++;
            break;
          }
        }
      }
    }
    return result;
  }