fork download
  1. #include<iostream>
  2. #include<algorithm>
  3.  
  4. using namespace std;
  5.  
  6. bool bin_search(int a[],int lo,int hi,int y)
  7. {
  8. while(lo<=hi)
  9. {
  10. int mid=(lo+hi)/2;
  11. if(a[mid]==y) return 1;
  12. if(a[mid]<y) lo=mid+1;
  13. else hi=mid-1;
  14. }
  15. return 0;
  16. }
  17.  
  18. int main()
  19. {
  20. ///freopen("input.txt","r",stdin);
  21. int n,q;
  22. cin >> n >> q;
  23. int a[n];
  24. for(int i=0;i<n;i++) cin >> a[i];
  25. sort(a,a+n);
  26. while(q--)
  27. {
  28. int x; cin >> x;
  29. int cnt=0;
  30. for(int i=0;i<n;i++)
  31. {
  32. if(a[i]==0 || x%a[i]!=0) continue;
  33. int y=x/a[i];
  34. if(bin_search(a,i+1,n-1,y)) cnt++;
  35. }
  36. if(cnt>0) cout << "Yes ";
  37. else cout << "No ";
  38. cout << cnt << endl;
  39. }
  40. }
  41. /**
  42. 11 5
  43. 10 6 3 20 2 30 7 13 11 14 5
  44. 60
  45. 91
  46. 121
  47. 14
  48. 70
  49. **/
  50.  
Success #stdin #stdout 0.01s 5332KB
stdin
11 5
10 6 3 20 2 30 7 13 11 14 5
60
91
121
14
70
stdout
Yes 3
Yes 1
No 0
Yes 1
Yes 2