PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000118. ƯCLN sau khi cộng (Row GCD)
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 sau khi cộng (Row GCD)
Row GCD
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given two positive integer arrays and , for each find the GCD of . Each query is independent; the array is unchanged.
Input
The first line contains ; the second contains values ; the third contains values .
Output
Print integers; the -th is the GCD for .
Subtasks
- Subtask 1 (20 points): ; ; ; .
- Subtask 2 (30 points): ; ; ; .
- Subtask 3 (50 points): ; ; ; .
Examples
Input
4 4
1 25 121 169
1 2 7 23
Output
2 3 8 24
Explanation
For , the shifted array is 2, 26, 122, 170 and has GCD 2. The remaining queries give 3, 8, and 24.