-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel2.cpp
More file actions
69 lines (61 loc) · 1.56 KB
/
level2.cpp
File metadata and controls
69 lines (61 loc) · 1.56 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> arrayA, vector<int> arrayB) {
int answer = 0;
vector<int> answers;
int minA = 100000001;
int maxA = 0;
int minB = 100000001;
int maxB = 0;
for (auto i: arrayA){
minA = minA > i ? i : minA;
maxA = maxA > i ? maxA : i;
}
for (auto i: arrayB){
minB = minB > i ? i : minB;
maxB = maxB > i ? maxB : i;
}
for (int i = 1; i * i <= maxA; i++){
bool pass = true;
for (int j =0; j < arrayA.size(); j++){
if (arrayA[j] % i != 0) {
pass = false;
break;
}
if (arrayB[j] % i == 0) {
pass = false;
break;
}
}
if (pass)
answers.push_back( i > maxA / i ? i : maxA / i);
}
for (int i = 1; i * i <= maxB; i++){
bool pass = true;
for (int j =0; j < arrayB.size(); j++){
if (arrayB[j] % i != 0) {
pass = false;
break;
}
if (arrayA[j] % i == 0) {
pass = false;
break;
}
}
if (pass)
answers.push_back( i > maxB / i ? i : maxB / i);
}
for (int i: answers){
cout << i << endl;
answer = answer > i ? answer : i;
}
return answer;
}
int main() {
vector<int> arrayA { 10, 20 };
vector<int> arrayB { 5, 17 };
cout << solution(arrayA, arrayB) << endl;
return 0;
}