库特有n个数,库特希望能从这n个数里选出来两个数,使他们的乘积为为m,请问库特能做到吗?如果存在库特能做到的方案,输出yes,否则输出no
Input
第一行两个数n ,m(2<=n<=1e5,0<=m<=1e9)
接下来一行n个数a[1]~a[n]。(0<=a[i]<=1e6)
Output
输出一行,yes或no
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
const int N=1e5+5;
typedef long long LL;
map<LL,int>vis;
LL a[N];
int main()
{
LL n,m;
while(cin>>n>>m)
{
int x,y,tmp,flag;
flag=0;
vis.clear();
for(int i=0;i<n;i++)
{
cin>>a[i];
x=a[i];
vis[x]++;
}
if(m==0&&vis[0]>0){cout<<"yes"<<endl;continue;}
if(m==0&&vis[0]==0){cout<<"no"<<endl;continue;}
for(int i=0;i<n;i++)
{
if(a[i]!=0&&m%a[i]==0)
{
tmp=m/a[i];
if(vis[tmp]>0&&tmp!=a[i])flag=1;
if(vis[tmp]>1&&tmp==a[i])flag=1;
}
}
if(flag==1)cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}