fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const double PI=acos(-1.0);
  5. #define ll long long
  6. int main()
  7. {
  8.  
  9. int i,j,k;
  10. int n,m;
  11.  
  12. cin>>m;
  13. int a[m];
  14. for ( i = 0; i < m; ++i)
  15. {
  16. cin>>a[i];
  17. }
  18. int x,check=0;
  19. for ( i = 0; i < m; ++i)
  20. {
  21. for ( j = i; j < m; ++j)
  22. {
  23. x=__gcd(a[i],a[j]);
  24. if(!binary_search(a,a+m,x))
  25. {
  26. //cout<<x<<endl;
  27. check=1;
  28.  
  29. }
  30. //else check=1;
  31. }
  32. }
  33. if(check)cout<<"-1\n";
  34. else
  35. {
  36. cout<<m<<endl;
  37. for ( i = 0; i < m; ++i)
  38. {
  39. cout<<a[i]<<" ";
  40. }
  41. cout<<endl;
  42. }
  43.  
  44.  
  45. return 0;
  46. }
Success #stdin #stdout 0s 4508KB
stdin
4
2 4 6 12
stdout
4
2 4 6 12