fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int t;cin >> t;
  7. while(t--)
  8. {
  9. int n,p;cin >> n >> p;
  10. //cout << n << " " << p << endl;
  11. int arr[n];
  12. // v stores divisors,v1 stores non divisors
  13. vector< pair <int,int> > v,v1;
  14.  
  15. for(int i = 0;i<n;i++){
  16. cin >> arr[i] ;
  17. // cout << arr[i] << endl;
  18. if(arr[i] != 1 && p%arr[i] == 0)
  19. {
  20. // cout << " uu" << endl;
  21. v.push_back(make_pair(arr[i],i));
  22. // cout << v[0].first << endl;
  23. }
  24. else if(arr[i] != 1 && p%arr[i] != 0){
  25. v1.push_back(make_pair(arr[i],i));
  26. //v2.push_back(arr[i]);
  27. }
  28. }
  29. // cout << "JJ" << endl;
  30. // cout << "dD" << v[0].first << endl;
  31. sort(v.begin(),v.end());
  32.  
  33. // cout << v[0].first << endl;
  34. vector<int> q(n,0);
  35. //cout << " V size " << v.size() << endl;
  36. //cout << v1[0].second << " v1[0]" << endl;
  37. if(v1.size() >= 1)
  38. {
  39. cout << "YES ";
  40. q[v1[0].second] = p/v1[0].first + 1;
  41. for(int i = 0;i<q.size();i++){
  42. cout << q[i] << " ";
  43.  
  44. }
  45. cout << endl;
  46. }
  47. else if(v.size() >=2 )
  48. {
  49.  
  50. int cp = 0;
  51. int i = 0,j=0;
  52. for(i = 0;i<v.size()-1;i++){
  53. for(j=i+1;j<v.size();j++)
  54. // cout << v[i].first << endl;
  55. {
  56. if(v[j].first % v[i].first != 0){
  57. cp++;
  58.  
  59. break;
  60. }
  61. }
  62. if(cp>=1)
  63. break;
  64. }
  65.  
  66. q[v[i].second] = (p/v[i].first) - 1;
  67. q[v[j].second] = 1;
  68. // cout << v[i].first <<" " << q[v[i].second] << endl;
  69. //cout << v[j].first << " " << q[v[j].second] << endl;
  70.  
  71.  
  72. // cout <<"ZZ" << endl;
  73. if(cp == 0)
  74. cout << "NO" << endl;
  75. else{
  76. cout << "YES " ;
  77. for(int i = 0;i<q.size();i++){
  78. cout << q[i] << " ";
  79. }
  80. cout << endl;
  81. }
  82. }
  83. else{
  84. //if(v.size() == 1)
  85. cout << "NO" << endl;
  86.  
  87. }
  88.  
  89.  
  90.  
  91.  
  92. }
  93. return 0;
  94. }
Success #stdin #stdout 0s 4452KB
stdin
1
2 20
4 10
stdout
YES 4 1