Advertisement
O_Egor

19(+)

Nov 10th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <numeric>
  6. using namespace std;
  7.  
  8. bool is_simple(int a)
  9. {
  10.     if (a == 1)
  11.         return 0;
  12.     if (a != 2)
  13.         for (int i = 2; i < sqrt(a) + 1; i++) {
  14.             if (!(a % i)) return 0;
  15.         }
  16.     return 1;
  17. }
  18. bool p(int a)
  19. {
  20.     return (a>0);
  21. }
  22. int main()
  23. {
  24.     int n,m;
  25.     cin >> n >> m;
  26.     vector <int> v1(n), v2(m), v3;
  27.     for (int i = 0; i < n; ++i)
  28.         cin >> v1[i];
  29.     for(int i = 0; i < m; ++i)
  30.         cin >> v2[i];
  31.     //for (it; it != v1.end(); ++it)
  32.     copy_if(v1.begin(), v1.end(), back_inserter(v3), p);
  33.     copy_if(v2.begin(), v2.end(), back_inserter(v3), p);
  34.     int s(v3.size());
  35.     int it1 = find_if(v3.begin(), v3.end(), is_simple) - v3.begin();
  36.     int it2 = find_if(v3.rbegin(), v3.rend(), is_simple) - v3.rbegin();
  37.     it2 = s - (it2 + 1);
  38.     //cout << it1 << ' ' << it2;
  39.     if (abs(it1 - it2) < 2 || it1 == s)
  40.         cout << "NO!";
  41.     else
  42.     {
  43.         cout << "First Index: " << it1 << '\n' << "Second Index: " << it2 << '\n';
  44.         int sum = accumulate(v3.begin()+(it1+1), v3.begin()+(it2), 0);
  45.         cout << "Summa = " << sum << '\n';
  46.         cout << "Srednnee arifmiticheskoe = " << sum / ((it2 - (it1 + 1)) * 1.);
  47.     }
  48.     /*for (int i = 0; i < s; ++i)
  49.         cout << v3[i] << ' ';*/
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement