PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000133. ƯCLN của tập con (GCD of Subset)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
ƯCLN của tập con (GCD of Subset)
GCD of Subset
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integer array and , for each position , choose exactly distinct indices including . Maximize the GCD of the selected values and output that optimum for every in the original order.
Input
The first line contains ; the second contains integers .
Output
Print exactly lines; line is the maximum GCD attainable with index included.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
5 2
3 4 6 7 12
Output
3
4
6
1
6
Explanation
Choose (3,6) for index 1 to get 3; (4,12) for index 2 to get 4; (6,12) for index 3 to get 6. For 7 no other element shares a divisor above 1; index 5 can pair 12 with 6 to get 6.