Codeforces Round 675 (Div. 2)
F
Boring Queries
Codeforces
2700
原题
← E→
翻译中…

Yura owns a quite ordinary and boring array $a$ of length $n$. 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 $q$ boring queries. Each query consists of two integers $x$ and $y$. Before answering a query, the bounds $l$ and $r$ for this query are calculated: $l = (last + x) \bmod n + 1$, $r = (last + y) \bmod n + 1$, where $last$ is the answer on the previous query (zero initially), and $\bmod$ is the remainder operation. Whenever $l \gt r$, they are swapped.

翻译中…

After Vladik computes $l$ and $r$ for a query, he is to compute the least common multiple (LCM) on the segment $[l; r]$ of the initial array $a$ modulo $10^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!

翻译中…

Input

翻译中…

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

翻译中…

The second line contains $n$ integers $a_i$ ($1 \le a_i \le 2 \cdot 10^5$) — the elements of the array.

翻译中…

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

翻译中…

The next $q$ lines contain two integers $x$ and $y$ each ($1 \le x, y \le n$) — the description of the corresponding query.

翻译中…

Output

翻译中…

Print $q$ integers — the answers for the queries.

翻译中…

Note

翻译中…

Consider the example:

翻译中…
  • boundaries for first query are $(0 + 1) \bmod 3 + 1 = 2$ and $(0 + 3) \bmod 3 + 1 = 1$. LCM for segment $[1, 2]$ is equal to $6$;
  • boundaries for second query are $(6 + 3) \bmod 3 + 1 = 1$ and $(6 + 3) \bmod 3 + 1 = 1$. LCM for segment $[1, 1]$ is equal to $2$;
  • boundaries for third query are $(2 + 2) \bmod 3 + 1 = 2$ and $(2 + 3) \bmod 3 + 1 = 3$. LCM for segment $[2, 3]$ is equal to $15$;
  • boundaries for fourth query are $(15 + 2) \bmod 3 + 1 = 3$ and $(15 + 3) \bmod 3 + 1 = 1$. LCM for segment $[1, 3]$ is equal to $30$.
翻译中…

样例

Input #1
3
2 3 5
4
1 3
3 3
2 3
2 3
Output #1
6
2
15
30
InputCopy OutputCopy
题目信息
题号
1422F
时间限制
3 s
内存限制
512 MB
标签
数据结构
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。