#include using namespace std; #ifndef ONLINE_JUDGE #include "algo/debug.h" #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long bool isDivisible(int x, const vector& nonDiv) { // Use binary search to check if x is divisible by any element in nonDiv for (int elem : nonDiv) { if (elem > x) break; // Since the array is sorted, no need to check further if (x % elem == 0) return true; } return false; } vector printNonDivisibleElements(const vector& arr) { int n = arr.size(); vector nonDiv; // To store non-divisible elements // Iterate through the sorted array for (int i = 0; i < n; ++i) { // Check if the current element is divisible by any in nonDiv if (!isDivisible(arr[i], nonDiv)) { nonDiv.push_back(arr[i]); // Add to non-divisible list } } // Print the result return nonDiv; } void solve() { int n, m; cin >> n >> m; vector a(n); for (auto &x : a) { cin >> x; } sort(a.begin(), a.end()); reverse(a.begin(), a.end()); a.pop_back(); reverse(a.begin(), a.end()); auto p = printNonDivisibleElements(a); for (auto &x : p) { int c = 0; for (int j = 0; j < a.size(); j++) { c += (a[j] % x == 0); } if (c != (m / x)) { cout << -1 << '\n'; return; } } cout << p.size() << "\n"; for (auto &x : p) { cout << x << " "; } } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else #endif ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) { solve(); } // cerr << "Time elapsed: " << ((long double)clock() / CLOCKS_PER_SEC) << " s.\n"; }