title: Count Pairs Whose Products Exist In Array 1
signature: count_pairs_whose_products_exist_in_array_1 <- 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(7L, 10L, 17L, 17L, 18L, 20L, 27L, 28L, 29L, 29L, 31L, 32L, 41L, 43L, 45L, 46L, 63L, 66L, 69L, 69L, 70L, 75L, 87L, 95L), 17L, 
          0L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-60L), 0L, 
          0L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 9L, 
          36L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(52L, 83L, 36L, 57L, 93L, 11L, 32L, 91L, 52L), 8L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -94L, -90L, -88L, -76L, -76L, -64L, -62L, -60L, -50L, -46L, -32L, -24L, -22L, -20L, -16L, -4L, -2L, 6L, 10L, 20L, 28L, 30L, 32L, 34L, 38L, 40L, 42L, 54L, 64L, 72L, 76L, 82L, 82L, 86L, 92L, 92L, 98L, 98L), 22L, 
          2L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L), 42L, 
          861L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(2L, 3L, 10L, 12L, 15L, 23L, 26L, 28L, 29L, 30L, 31L, 31L, 33L, 33L, 35L, 41L, 45L, 48L, 50L, 50L, 53L, 53L, 56L, 65L, 66L, 67L, 68L, 68L, 72L, 72L, 75L, 76L, 79L, 82L, 90L, 94L, 94L, 95L, 97L, 99L), 35L, 
          9L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(14L, 36L, -54L, -54L), 3L, 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L), 12L, 
          66L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(5L, 69L, 37L, 80L, 21L, 98L, 70L, 70L, 74L, 95L, 6L, 67L, 44L, 55L, 52L, 89L, 84L, 99L, 65L, 52L), 12L, 
          0L
      )))
  
  }
  
  main()
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;
  }