题库练习 Burenka, an Array and Queries
← 上一题 下一题 →

A15326 | Burenka, an Array and Queries

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Eugene got Burenka an array $a$ of length $n$ of integers from $1$ to $m$ for her birthday. Burenka knows that Eugene really likes coprime integers (integers $x$ and $y$ such that they have only one common factor (equal to $1$ )) so she wants to to ask Eugene $q$ questions about the present.

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

Help Eugene answer all the questions!

输入格式

In the first line of input there are four integers $n$ , $m$ , $C$ , $q$ ( $1 \leq n, q \leq 10^5$ , $1 \leq m \leq 2\cdot 10^4$ , $1 \leq C \leq 10^5$ ) — the length of the array $a$ , the maximum possible value of $a_{i}$ , the value $C$ , and the number of queries.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_{i} \leq m$ ) — the array $a$ .

In the next $q$ lines the queries are given. Each query consists of two integers $l$ and $r$ ( $1 \leq l \leq r \leq n$ ).

输出格式

Print $q$ integers — the answers to Burenka's queries.

输入输出样例

输入 #1
5 5 5 3
1 2 3 2 5
1 1
2 4
4 5
输出 #1
5
2
2
C++ 编辑器
输入
输出