CF475D.CGCDSSQ

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Given a sequence of integers _a_1, ..., a__n and q queries _x_1, ..., x__q on it. For each query x__i you have to count the number of pairs (l, r) such that 1 ≤ l ≤ r ≤ n and gcd(a__l, a__l + 1, ..., a__r) = x__i.

is a greatest common divisor of _v_1, _v_2, ..., v__n, that is equal to a largest positive integer that divides all v__i.

给定一个整数序列 a1,…,ana_1, \dots, a_n 和 qq 个查询 x1,…,xqx_1, \dots, x_q。对每个查询 xix_i,你需要统计满足 1≤l≤r≤n1 \le l \le r \le n 且 gcd⁡(al,al+1,…,ar)=xi\gcd(a_l, a_{l+1}, \dots, a_r) = x_i 的区间对 (l,r)(l, r) 的数量。

表示 v1,v2,…,vnv_1, v_2, \dots, v_n 的最大公约数(GCD),即能整除所有 viv_i 的最大正整数。

输入格式

The first line of the input contains integer n, (1 ≤ n ≤ 105), denoting the length of the sequence. The next line contains n space separated integers _a_1, ..., a__n, (1 ≤ a__i ≤ 109).

The third line of the input contains integer q, (1 ≤ q ≤ 3 × 105), denoting the number of queries. Then follows q lines, each contain an integer x__i, (1 ≤ x__i ≤ 109).

输入的第一行包含一个整数 nn(1 ≤ n ≤ 1051 \leq n \leq 10^5),表示序列的长度。
第二行包含 nn 个以空格分隔的整数 a1, …, ana_1, \ldots, a_n(1 ≤ ai ≤ 1091 \leq a_i \leq 10^9)。

输入的第三行包含一个整数 qq(1 ≤ q ≤ 3 × 1051 \leq q \leq 3 \times 10^5),表示查询的次数。
随后是 qq 行,每行包含一个整数 xix_i(1 ≤ xi ≤ 1091 \leq x_i \leq 10^9)。

输出格式

For each query print the result in a separate line.

对每个查询,在单独的一行中输出结果。

输入输出样例

  • 输入#1

    3
    2 6 3
    5
    1
    2
    3
    4
    6

    输出#1

    1
    2
    2
    0
    1
  • 输入#2

    7
    10 20 3 15 1000 60 16
    10
    1
    2
    3
    4
    5
    6
    10
    20
    60
    1000

    输出#2

    14
    0
    2
    2
    2
    0
    2
    2
    1
    1

输入解题思路,AI测评打分。不知道怎么写?

首页