CF1422F.Boring Queries

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Yura owns a quite ordinary and boring array aa of length nn. You think there is nothing more boring than that, but Vladik doesn't agree!

In order to make Yura's array even more boring, Vladik makes qq boring queries. Each query consists of two integers xx and yy. Before answering a query, the bounds ll and rr for this query are calculated: l=(last+x) mod n+1l = (last + x) \bmod n + 1, r=(last+y) mod n+1r = (last + y) \bmod n + 1, where lastlast is the answer on the previous query (zero initially), and  mod \bmod is the remainder operation. Whenever l>rl \gt r, they are swapped.

After Vladik computes ll and rr for a query, he is to compute the least common multiple (LCM) on the segment [l;r][l; r] of the initial array aa modulo 109+710^9 + 7. LCM of a multiset of integers is the smallest positive integer that is divisible by all the elements of the multiset. The obtained LCM is the answer for this query.

Help Vladik and compute the answer for each query!

尤拉拥有一个非常普通且乏味的长度为 nn 的数组 aa。你认为这已经无聊至极,但弗拉迪克却并不认同!

为了使尤拉的数组变得更加乏味,弗拉迪克会进行 qq 次“乏味”的查询。每次查询包含两个整数 xx 和 yy。在回答每次查询前,需先计算该查询的边界 ll 和 rr:

l=(last+x) mod n+1,r=(last+y) mod n+1,l = (last + x) \bmod n + 1,\quad r = (last + y) \bmod n + 1,

其中 lastlast 是上一次查询的答案(初始时为 00), mod \bmod 表示取余运算。若计算得到 l>rl > r,则交换 ll 与 rr 的值。

在弗拉迪克为某次查询算出 ll 和 rr 后,他需要计算原数组 aa 在区间 [l;r][l; r] 上所有元素的最小公倍数(LCM),并对 109+710^9 + 7 取模。一个整数多重集的 LCM 是能被该多重集中所有元素整除的最小正整数。该 LCM 即为本次查询的答案。

请帮助弗拉迪克,计算每次查询的答案!

输入格式

The first line contains a single integer nn (1≤n≤1051 \le n \le 10^5) — the length of the array.

The second line contains nn integers aia_i (1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5) — the elements of the array.

The third line contains a single integer qq (1≤q≤1051 \le q \le 10^5) — the number of queries.

The next qq lines contain two integers xx and yy each (1≤x,y≤n1 \le x, y \le n) — the description of the corresponding query.

第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)—— 数组的长度。

第二行包含 nn 个整数 aia_i(1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5)—— 数组的元素。

第三行包含一个整数 qq(1≤q≤1051 \le q \le 10^5)—— 查询的数量。

接下来的 qq 行,每行包含两个整数 xx 和 yy(1≤x,y≤n1 \le x, y \le n)—— 对应查询的描述。

输出格式

Print qq integers — the answers for the queries.

输出 qq 个整数——各查询的答案。

输入输出样例

  • 输入#1

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

    输出#1

    6
    2
    15
    30

说明/提示

Consider the example:

  • boundaries for first query are (0+1) mod 3+1=2(0 + 1) \bmod 3 + 1 = 2 and (0+3) mod 3+1=1(0 + 3) \bmod 3 + 1 = 1. LCM for segment [1,2][1, 2] is equal to 66;
  • boundaries for second query are (6+3) mod 3+1=1(6 + 3) \bmod 3 + 1 = 1 and (6+3) mod 3+1=1(6 + 3) \bmod 3 + 1 = 1. LCM for segment [1,1][1, 1] is equal to 22;
  • boundaries for third query are (2+2) mod 3+1=2(2 + 2) \bmod 3 + 1 = 2 and (2+3) mod 3+1=3(2 + 3) \bmod 3 + 1 = 3. LCM for segment [2,3][2, 3] is equal to 1515;
  • boundaries for fourth query are (15+2) mod 3+1=3(15 + 2) \bmod 3 + 1 = 3 and (15+3) mod 3+1=1(15 + 3) \bmod 3 + 1 = 1. LCM for segment [1,3][1, 3] is equal to 3030.

考虑如下示例:

  • 第一个查询的边界为 (0+1) mod 3+1=2(0 + 1) \bmod 3 + 1 = 2 和 (0+3) mod 3+1=1(0 + 3) \bmod 3 + 1 = 1,区间 [1,2][1, 2] 的最小公倍数(LCM)为 66;
  • 第二个查询的边界为 (6+3) mod 3+1=1(6 + 3) \bmod 3 + 1 = 1 和 (6+3) mod 3+1=1(6 + 3) \bmod 3 + 1 = 1,区间 [1,1][1, 1] 的最小公倍数为 22;
  • 第三个查询的边界为 (2+2) mod 3+1=2(2 + 2) \bmod 3 + 1 = 2 和 (2+3) mod 3+1=3(2 + 3) \bmod 3 + 1 = 3,区间 [2,3][2, 3] 的最小公倍数为 1515;
  • 第四个查询的边界为 (15+2) mod 3+1=3(15 + 2) \bmod 3 + 1 = 3 和 (15+3) mod 3+1=1(15 + 3) \bmod 3 + 1 = 1,区间 [1,3][1, 3] 的最小公倍数为 3030。

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

首页