Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <cmath>
- #include <algorithm>
- #include <numeric>
- using namespace std;
- bool is_simple(int a)
- {
- if (a == 1)
- return 0;
- if (a != 2)
- for (int i = 2; i < sqrt(a) + 1; i++) {
- if (!(a % i)) return 0;
- }
- return 1;
- }
- bool p(int a)
- {
- return (a>0);
- }
- int main()
- {
- int n,m;
- cin >> n >> m;
- vector <int> v1(n), v2(m), v3;
- for (int i = 0; i < n; ++i)
- cin >> v1[i];
- for(int i = 0; i < m; ++i)
- cin >> v2[i];
- //for (it; it != v1.end(); ++it)
- copy_if(v1.begin(), v1.end(), back_inserter(v3), p);
- copy_if(v2.begin(), v2.end(), back_inserter(v3), p);
- int s(v3.size());
- int it1 = find_if(v3.begin(), v3.end(), is_simple) - v3.begin();
- int it2 = find_if(v3.rbegin(), v3.rend(), is_simple) - v3.rbegin();
- it2 = s - (it2 + 1);
- //cout << it1 << ' ' << it2;
- if (abs(it1 - it2) < 2 || it1 == s)
- cout << "NO!";
- else
- {
- cout << "First Index: " << it1 << '\n' << "Second Index: " << it2 << '\n';
- int sum = accumulate(v3.begin()+(it1+1), v3.begin()+(it2), 0);
- cout << "Summa = " << sum << '\n';
- cout << "Srednnee arifmiticheskoe = " << sum / ((it2 - (it1 + 1)) * 1.);
- }
- /*for (int i = 0; i < s; ++i)
- cout << v3[i] << ' ';*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement