PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000092. Tối đa hóa BCNN của hai ƯCLN (LCM of GCDs)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tối đa hóa BCNN của hai ƯCLN (LCM of GCDs)
LCM of GCDs
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are packs, each containing two cards labeled and . Two bags, red and blue, are initially empty. For each pack, place exactly one card into the red bag and the other into the blue bag. After processing all packs, let be the GCD of the numbers in the red bag and the GCD of the numbers in the blue bag. The score is . Find the maximum possible score.
Input
The first line contains , followed by lines; line contains .
Output
Print the maximum achievable score.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
2
2 15
10 6
Output
10
Explanation
Put and into the red bag, and and into the blue bag. Then , , so the score is , which is optimal.