-
Notifications
You must be signed in to change notification settings - Fork 0
/
G.cpp
64 lines (54 loc) · 1.42 KB
/
G.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
55
56
57
58
59
60
61
62
63
64
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <algo/debug.h>
#else
#define debug(...) void(31)
#endif
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define FORD(i, b, a) for (int i = (int)b; i >= (int)a; --i)
#define EACH(v, a) for (auto& v : a)
#define SZ(a) ((int) a.size())
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
int main() {
#ifdef LOCAL
freopen("inp/G1.in", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
int nTest;
cin >> nTest;
debug(nTest);
REP(_, nTest) {
int m, n;
cin >> m >> n;
vi a(m), b(n);
REP(i, m) cin >> a[i];
REP(i, n) cin >> b[i];
map<int, int> fA, fB;
EACH(ai, a) fA[ai]++;
EACH(bi, b) fB[bi]++;
map<pii, int> cnt;
EACH(ai, fA) EACH(bi, fB) {
int freq = min(ai.second, bi.second);
int g = gcd(ai.first, bi.first);
int fa = ai.first / g, fb = bi.first / g;
cnt[{fa, fb}] += freq;
}
int maxFreq = 0;
EACH(v, cnt) {
maxFreq = max(maxFreq, v.second);
}
cout << (n + m - maxFreq) << endl;
}
}