-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2.cpp
More file actions
43 lines (37 loc) · 1.03 KB
/
day2.cpp
File metadata and controls
43 lines (37 loc) · 1.03 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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int N, M;
cin >> N >> M;
int H[1000], A[1000];
for (int i = 0; i < N; i++) cin >> H[i];
for (int i = 0; i < M; i++) cin >> A[i];
int divisor_count[100001] = {0};
for (int i = 0; i < N; i++) {
for (int d = 1; d * d <= H[i]; d++) {
if (H[i] % d == 0) {
divisor_count[d]++;
if (d != H[i] / d) divisor_count[H[i] / d]++;
}
}
}
int max_count = 0;
int best_luckiness = 100001;
for (int i = 0; i < M; i++) {
int count = divisor_count[A[i]];
if (count > max_count || (count == max_count && A[i] < best_luckiness)) {
max_count = count;
best_luckiness = A[i];
}
}
cout << best_luckiness << endl;
}
return 0;
}