PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000153. Đếm đoạn con theo GCD (CGCDSSQ)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm đoạn con theo GCD (CGCDSSQ)
CGCDSSQ
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a sequence of positive integers . For any , define the interval GCD as .
Each of queries gives a positive integer . Count the pairs for which the GCD of that contiguous subarray is exactly . Different index pairs are counted separately, and the array never changes.
Input
The first line contains ; the second contains values . The next line contains , followed by lines, each containing .
Output
For each query, output the number of contiguous subarrays whose GCD equals .
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
3
2 6 3
5
1
2
3
4
6
Output
1
2
2
0
1
Explanation
The six subarrays have GCDs: , , , , , and . Thus the counts for are .