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!
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$ ).
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
Here's an explanation for the example:
1. in the first query, the product is equal to $1$ , which is coprime with $1,2,3,4,5$ .
2. in the second query, the product is equal to $12$ , which is coprime with $1$ and $5$ .
3. in the third query, the product is equal to $10$ , which is coprime with $1$ and $3$ .
1. in the first query, the product is equal to $1$ , which is coprime with $1,2,3,4,5$ .
2. in the second query, the product is equal to $12$ , which is coprime with $1$ and $5$ .
3. in the third query, the product is equal to $10$ , which is coprime with $1$ and $3$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted