#GL0000355. Ước số và bội số (Factors and Multiples)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Ước số và bội số (Factors and Multiples)
Factors and Multiples
Source: LightOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given two sets of positive integers (with elements) and (with elements), delete some elements from either set so that no remaining pair , with , , satisfies .
Find the minimum total number of deleted elements. A value cannot be changed, only deleted.
PHOJ adaptation: One case per file; do not print the original LightOJ Case k: prefix.
Input
- First line: .
- Second line: distinct positive integers in .
- Third line: .
- Fourth line: distinct positive integers in .
Output
A single integer: the minimum number of deletions.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
- Elements within either set are distinct positive integers.
Examples
Example 1
Input
4
2 3 4 5
4
6 7 8 9
Output
3
Explanation
Delete 2 and 3 from A and 8 from B. Then A={4,5}, B={6,7,9}, with no divisibility edge; fewer than 3 deletions cannot suffice.
Example 2
Input
3
100 200 300
1
150
Output
0
Explanation
150 is not divisible by 100, 200, or 300, hence no deletion is needed.
Example 3
Input
2
2 3
1
6
Output
1
Explanation
Both 2 and 3 divide 6; deleting the sole B element eliminates both edges.