kikit
6/21/2016 - 3:40 PM

Pair with given product

Pair with given product

/*
http://ideone.com/BySlXT
http://www.geeksforgeeks.org/pair-with-given-product-set-1-find-if-any-pair-exists/
http://www.practice.geeksforgeeks.org/problem-page.php?pid=667
*/


#include <iostream>
#include <set>
using namespace std;

bool isPro(int a[], int n, int p){
	if(n < 2)
		return false;
	
	set<int> s;
	for(int i=0; i<n; i++){
		if(a[i] == 0){
			if(p == 0)
				return false;
			else
				continue;
		}
		if(p % a[i] == 0){
			if(s.find(p / a[i]) != s.end())
				return true;
				
			s.insert(a[i]);
		}
	}
	return false;
}
int main() {
	int t, n, p;
	cin >> t;
	while(t--){
		cin >> n >> p;
		int a[1001];
		for(int i=0; i<n; i++)
			cin >> a[i];
		
		if(isPro(a, n, p))
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}