CF1493D.GCD of an Array

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given an array aa of length nn . You are asked to process qq queries of the following format: given integers ii and xx , multiply aia_i by xx .

After processing each query you need to output the greatest common divisor (GCD) of all elements of the array aa .

Since the answer can be too large, you are asked to output it modulo 109+710^9+7 .

输入格式

The first line contains two integers — nn and qq ( 1n,q21051 \le n, q \le 2 \cdot 10^5 ).

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai21051 \le a_i \le 2 \cdot 10^5 ) — the elements of the array aa before the changes.

The next qq lines contain queries in the following format: each line contains two integers ii and xx ( 1in1 \le i \le n , 1x21051 \le x \le 2 \cdot 10^5 ).

输出格式

Print qq lines: after processing each query output the GCD of all elements modulo 109+710^9+7 on a separate line.

输入输出样例

  • 输入#1

    4 3
    1 6 8 12
    1 12
    2 3
    3 3

    输出#1

    2
    2
    6

说明/提示

After the first query the array is [12,6,8,12][12, 6, 8, 12] , gcd(12,6,8,12)=2\operatorname{gcd}(12, 6, 8, 12) = 2 .

After the second query — [12,18,8,12][12, 18, 8, 12] , gcd(12,18,8,12)=2\operatorname{gcd}(12, 18, 8, 12) = 2 .

After the third query — [12,18,24,12][12, 18, 24, 12] , gcd(12,18,24,12)=6\operatorname{gcd}(12, 18, 24, 12) = 6 .

Here the gcd\operatorname{gcd} function denotes the greatest common divisor.

首页