Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using llong = long long;
- llong gcd(llong a, llong b)
- {
- if (b == 0)
- return a;
- else
- return gcd(b, a % b);
- }
- int main() {
- llong n, d;
- cin >> n >> d;
- vector<llong> v(n);
- for (auto i = 0; i < n; i++)
- {
- cin >> v[i];
- }
- vector<llong> a;
- for (auto e : v)
- if (e % d == 0)
- a.push_back(e);
- vector<llong> res;
- for (auto e : a)
- if (gcd(d, e) == d)
- res.push_back(e);
- if (res.empty())
- {
- cout << -1;
- return 0;
- }
- cout << res.size() << endl;
- for (auto e : res)
- cout << e << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement