-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q2.cpp
54 lines (52 loc) · 998 Bytes
/
Q2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
using namespace std;
#include <map>
#include <vector>
map<int, int> mp;
int func(int val) // 0,非质数
{
for (int i = 2; i < val; i++)
{
if (val % i == 0)
return 0;
}
return 1;
}
int getNumber(vector<int> &a)
{
// write code here
int n = a.size();
mp[1] = 0;
for (int i = 2; i <= n; i++)
{
mp[i] = func(i);
}
// cout << "ok";
auto buff = a;
while (buff.size() != 1)
{
int len = buff.size();
vector<int> temp;
cout << endl;
for (int i = 0; i < len; i++)
{
if (mp[i + 1] == 1)
{
temp.push_back(buff[i]);
cout << buff[i] << " ";
}
}
buff = temp;
if (buff.size() == 1)
break;
}
return buff[0];
}
int main()
{
// vector<int> a = {3, 1, 1, 4, 5, 6};
vector<int> a = {1, 2, 3, 4};
cout << getNumber(a);
getchar();
return 0;
}