fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. const int N = 2e6;
  5.  
  6. int p[N+1], freq[N+1];
  7.  
  8. int main() {
  9.  
  10. for (int i = 2; i <= N; i++) p[i] = 1;
  11. for (long long i = 2; i <= N; i++) {
  12. if (!p[i]) continue;
  13. for (long long j = i * i; j <= N; j += i)
  14. p[j] = 0;
  15. }
  16.  
  17. int n; cin >> n;
  18. vector<int> a(n);
  19. for (auto& i : a) {
  20. cin >> i, freq[i]++;
  21. if (i != 1 && freq[i] > 1) freq[i] = 1;
  22. }
  23.  
  24. int ans = freq[1];
  25. for (auto& i : a)
  26. for (auto& j: a)
  27. if (i != j && p[i + j])
  28. ans = max(ans, freq[i] + freq[j]);
  29.  
  30. if (ans == freq[1] && ans != 0) {
  31. cout << ans << endl;
  32. while (ans--) cout << "1 ";
  33. return 0;
  34. }
  35.  
  36. for (auto& i : a)
  37. for (auto& j: a)
  38. if (i != j && p[i + j] && ans == freq[i] + freq[j]) {
  39. cout << ans << endl;
  40. while (freq[i]--) cout << i << " ";
  41. while (freq[j]--) cout << j << " ";
  42. return 0;
  43. }
  44.  
  45. cout << 1 << endl << a[0];
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0.02s 11584KB
stdin
2
83 14
stdout
2
83 14