Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- bool simple(int n)
- {
- if (n < 2) return false;
- for (int i = 2; i <= n / 2; i++)
- if (!(n % i)) return false;
- return true;
- }
- int task(int mas[], int n, int newmas[])
- {
- int k = 0;
- if (check(mas, n)) {
- for (int i = n-1; i >= 0; i--){
- if (!simple(mas[i]))
- {
- newmas[k] = mas[i];
- k++;
- }
- }
- }
- return k;
- }
- bool check(int mas[], int n) {
- bool polchecker = true;
- bool simplechecker = false;
- for (int i = 0; i < n; i++) {
- if (mas[i] < 0) polchecker = false;
- if (simple(mas[i])) simplechecker = true;
- }
- if (simplechecker && polchecker) return true;
- else return false;
- }
Add Comment
Please, Sign In to add comment