CF1422F.Boring Queries

普及/提高-

通过率:0%

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)modn+1l = (last + x) \bmod n + 1 , r=(last+y)modn+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 > 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!

输入格式

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

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

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

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

输出格式

Print qq integers — the answers for the queries.

输入输出样例

  • 输入#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)mod3+1=2(0 + 1) \bmod 3 + 1 = 2 and (0+3)mod3+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)mod3+1=1(6 + 3) \bmod 3 + 1 = 1 and (6+3)mod3+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)mod3+1=2(2 + 2) \bmod 3 + 1 = 2 and (2+3)mod3+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)mod3+1=3(15 + 2) \bmod 3 + 1 = 3 and (15+3)mod3+1=1(15 + 3) \bmod 3 + 1 = 1 . LCM for segment [1,3][1, 3] is equal to 3030 .
首页