• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest May 16th, 2018 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #include <iostream>
2. #include <vector>
3.
4. using namespace std;
5.
6. bool isPrime(int num)
7. {
8.     if(num==1)
9.         return false;
10.     if(num==2)
11.         return true;
12.     for(int i=2; i<num/2+1; i++)
13.         if(num%i==0)
14.             return false;
15.     return true;
16. }
17.
18. vector<int>* findAllPrimesTill(int num)
19. {
20.     vector<int> *result = new vector<int>();
21.     for(int i = 2; i<num; i++)
22.         if(isPrime(i))
23.             result->push_back(i);
24.     return result;
25. }
26.
27. int getMax(int *arr, int len)
28. {
29.     int maxV = arr[0];
30.     for(int i=0; i<len; i++)
31.         if(maxV<arr[i])
32.             maxV = arr[i];
33.     return maxV;
34. }
35.
36. vector<int> *filterPrimes(vector<int> *vPtr, int num){
37.     vector<int> *resultV = new vector<int>();
38.     for(int i =0; i<vPtr->size();i++)
39.         if(num%vPtr->at(i)==0)
40.             resultV->push_back(vPtr->at(i));
41.     return resultV;
42. }
43.
44. void printVector(vector<int> *vPtr){
45.     for(int i=0;i<vPtr->size();i++)
46.     {
47.         cout<<vPtr->at(i)<<" ";
48.     }
49.     cout<<endl;
50. }
51.
52. int main()
53. {
54.     int n = 7;
55.     int arr[n];
56.     int sum = 0;
57.     for(int i=0; i<n; i++)
58.     {
59.         cin>>arr[i];
60.         sum+=arr[i];
61.     }
62.
63.     int maxArrVal = getMax(arr,n);
64.     //cout<<maxArrVal<<endl;
65.     vector<int> *primes = findAllPrimesTill(maxArrVal/2+2);
66.
67.     primes = filterPrimes(primes, sum);
68.
69.     cout<<sum<<endl;
70.     printVector(primes);
71.     return 0;
72. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top