fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. #include <climits>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <numeric>
  8.  
  9. using namespace std;
  10. const int MOD = 1000000007;
  11.  
  12. bool isPrime(long long n) {
  13. for (long long i = 2; i * i <= n;i++) {
  14. if (n % i == 0) {
  15. return false;
  16. }
  17. }
  18. return n >= 2;
  19. }
  20.  
  21. int main() {
  22. vector<int> v;
  23.  
  24. int n;cin >> n;
  25. for (int i = 1;i <= n;i++) {
  26. int value;cin >> value;
  27. v.push_back(value);
  28. }
  29.  
  30. int currentLength = 0, maxLength = 0;
  31. int currentSum = 0, maxSum = 0;
  32. int index = -1;
  33.  
  34. for (int i = 0;i < n;i++) {
  35. if (isPrime(v[i])) {
  36. currentLength++;
  37. currentSum += v[i];
  38. }
  39. else {
  40. currentLength = 0;
  41. currentSum = 0;
  42. }
  43. if (currentLength > maxLength) {
  44. maxLength = currentLength;
  45. maxSum = currentSum;
  46. index = i - maxLength + 1;
  47. }
  48. else if (currentLength == maxLength) {
  49. if (currentSum > maxSum) {
  50. maxLength = currentLength;
  51. maxSum = currentSum;
  52. index = i - maxLength + 1;
  53. }
  54. }
  55. }
  56. if (index == -1) {
  57. cout << "NOT FOUND";
  58. }
  59. else {
  60. cout << maxLength << endl;
  61. for (int i = 0;i < maxLength;i++) {
  62. cout << v[index + i] << " ";
  63. }
  64. }
  65. }
  66.  
  67.  
  68.  
  69.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
NOT FOUND