title: Pair With Given Product Set 1 Find If Any Pair Exists 1
signature: bool pairWithGivenProductSet1FindIfAnyPairExists1(vector<int> arr, int n, int x) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(bool actual, bool expected){
      return actual == expected;
  }
  
  string driver(vector<int> arr, int n, int x, bool expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(arr, n, x), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver({1, 2, 3, 7, 23, 23, 25, 27, 37, 42, 53, 56, 58, 61, 69, 78, 79, 84, 85, 86, 90, 93, 95}, 15, 17, false); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver({-10, -18, 88, -36, 78, 66, -70, -34, -88, -98, -70, -4, -94, -92, -76, -78, -30, -48, -72, 86, -64, 38, -80, 20, 70, -32, -90, 74, -78, 12, -54, 88, 38, -96, 28}, 17, 22, false); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 1, 1}, 9, 5, false); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver({83, 61, 55, 89, 16, 78, 44, 54, 22, 49, 58, 62, 53, 99, 35, 83, 29, 19, 96, 39, 60, 6, 34, 67, 43, 29, 46, 3, 81, 78, 80, 39, 86, 78, 21}, 23, 27, false); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver({-96, -88, -80, -62, -58, -56, -54, -52, -34, -20, -6, -2, 6, 20, 52, 54, 70, 72, 80, 82, 94}, 18, 12, true); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 1, 1, 0, 0, 1, 1, 1}, 4, 6, false); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver({8, 11, 11, 20, 22, 23, 26, 27, 31, 38, 40, 40, 45, 46, 46, 48, 50, 61, 73, 76, 78, 78, 79, 80, 81, 84, 90, 91, 93, 95}, 24, 28, false); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver({18}, 0, 0, false); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 37, 39, false); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver({19, 37, 47, 40, 72, 59, 51, 53, 92, 3, 21, 81, 29, 48, 97, 59, 10, 74, 11, 37, 49, 95, 88, 85, 6, 26, 76, 33}, 22, 21, false); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def pair_with_given_product_set_1_find_if_any_pair_exists_1(arr, n, x):
      if (n < 2):
          return False
      s = set()
      for i in range(0, n):
          if (arr[i] == 0):
              if (x == 0):
                  return True
              else:
                  continue
          if ((x % arr[i]) == 0):
              if ((x // arr[i]) in s):
                  return True
              s.add(arr[i])
      return False
source_cpp: bool pair_with_given_product_set_1_find_if_any_pair_exists_1(vector<int> arr, int n, int x) {
    if ( n < 2 ) return false;
    unordered_set < int > s;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( arr [ i ] == 0 ) {
        if ( x == 0 ) return true;
        else continue;
      }
      if ( x % arr [ i ] == 0 ) {
        if ( s . find ( x / arr [ i ] ) != s . end ( ) ) return true;
        s . insert ( arr [ i ] );
      }
    }
    return false;
  }