Advertisement
Guest User

Untitled

a guest
Dec 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using llong = long long;
  4.  
  5. llong gcd(llong a, llong b)
  6. {
  7. if (b == 0)
  8. return a;
  9. else
  10. return gcd(b, a % b);
  11. }
  12.  
  13. int main() {
  14. llong n, d;
  15. cin >> n >> d;
  16. vector<llong> v(n);
  17.  
  18. for (auto i = 0; i < n; i++)
  19. {
  20. cin >> v[i];
  21. }
  22.  
  23. vector<llong> a;
  24. for (auto e : v)
  25. if (e % d == 0)
  26. a.push_back(e);
  27.  
  28. vector<llong> res;
  29. for (auto e : a)
  30. if (gcd(d, e) == d)
  31. res.push_back(e);
  32.  
  33. if (res.empty())
  34. {
  35. cout << -1;
  36. return 0;
  37. }
  38.  
  39. cout << res.size() << endl;
  40. for (auto e : res)
  41. cout << e << " ";
  42.  
  43.  
  44.  
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement