PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000134. Ước chung yếu (Weakened Common Divisor)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ước chung yếu (Weakened Common Divisor)
Weakened Common Divisor
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given pairs , an integer is called a weakened common divisor if, for every pair, divides at least one of or . Output any such divisor, or -1 if none exists. No optimization of is required.
Input
The first line contains , followed by lines each containing .
Output
Print any valid integer , or -1 if none exists.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
3
17 18
15 24
12 15
Output
2
Explanation
The value 2 divides 18 in pair 1, 24 in pair 2, and 12 in pair 3. Hence every pair contains an integer divisible by 2, so the output is valid.