CF1718F.Burenka, an Array and Queries

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Eugene got Burenka an array aa of length nn of integers from 11 to mm for her birthday. Burenka knows that Eugene really likes coprime integers (integers xx and yy such that they have only one common factor (equal to 11)) so she wants to to ask Eugene qq questions about the present.

Each time Burenka will choose a subsegment al,al+1,…,ara_l, a_{l + 1}, \ldots, a_r of array aa, and compute the product of these numbers p=al⋅al+1⋅…⋅arp = a_l \cdot a_{l + 1} \cdot \ldots \cdot a_r. Then she will ask Eugene to count the number of integers between 11 and CC inclusive which are coprime with pp.

Help Eugene answer all the questions!

尤金送给布伦卡一个长度为 nn 的数组 aa 作为生日礼物,其中每个元素都是从 11 到 mm 的整数。布伦卡知道尤金非常喜欢互质整数(即两个整数 xx 和 yy 的唯一公共因数为 11),因此她打算向尤金提出 qq 个关于该数组的问题。

每次,布伦卡会选择数组 aa 的一个子段 al,al+1,…,ara_l, a_{l + 1}, \ldots, a_r,并计算这些数的乘积 p=al⋅al+1⋅…⋅arp = a_l \cdot a_{l + 1} \cdot \ldots \cdot a_r。接着,她会请尤金计算在 11 到 CC(含端点)之间与 pp 互质的整数的个数。

请帮助尤金回答所有这些问题!

输入格式

In the first line of input there are four integers nn, mm, CC, qq (1≤n,q≤1051 \leq n, q \leq 10^5, 1≤m≤2⋅1041 \leq m \leq 2\cdot 10^4, 1≤C≤1051 \leq C \leq 10^5) — the length of the array aa, the maximum possible value of aia_{i}, the value CC, and the number of queries.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤m1 \leq a_{i} \leq m) — the array aa .

In the next qq lines the queries are given. Each query consists of two integers ll and rr (1≤l≤r≤n1 \leq l \leq r \leq n).

输入的第一行包含四个整数 nn、mm、CC、qq(1≤n,q≤1051 \leq n, q \leq 10^5,1≤m≤2⋅1041 \leq m \leq 2\cdot 10^4,1≤C≤1051 \leq C \leq 10^5)——分别表示数组 aa 的长度、aia_{i} 的最大可能值、数值 CC 以及查询次数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤m1 \leq a_{i} \leq m)——即数组 aa。

接下来 qq 行给出查询。每个查询包含两个整数 ll 和 rr(1≤l≤r≤n1 \leq l \leq r \leq n)。

输出格式

Print qq integers — the answers to Burenka's queries.

输出 qq 个整数——即布伦卡各个查询的答案。

输入输出样例

  • 输入#1

    5 5 5 3
    1 2 3 2 5
    1 1
    2 4
    4 5

    输出#1

    5
    2
    2

说明/提示

Here's an explanation for the example:

  1. in the first query, the product is equal to 11, which is coprime with 1,2,3,4,51,2,3,4,5.
  2. in the second query, the product is equal to 1212, which is coprime with 11 and 55.
  3. in the third query, the product is equal to 1010, which is coprime with 11 and 33.

以下是该示例的解释:

  1. 在第一个查询中,乘积等于 11,它与 1,2,3,4,51,2,3,4,5 均互质。
  2. 在第二个查询中,乘积等于 1212,它与 11 和 55 互质。
  3. 在第三个查询中,乘积等于 1010,它与 11 和 33 互质。

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

首页