CF1493D.GCD of an Array

提高+/省选-

通过率:0%

时间限制:2.50s

内存限制:256MB

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.

给你一个长度为 nn 的数组 aa。你需要处理 qq 个如下格式的查询:给定整数 ii 和 xx,将 aia_i 乘以 xx。

每次查询处理完毕后,你需要输出数组 aa 中所有元素的最大公约数(GCD)。

由于答案可能过大,你只需输出其对 109+710^9+7 取模的结果。

输入格式

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

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤2⋅1051 \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 (1≤i≤n1 \le i \le n, 1≤x≤2⋅1051 \le x \le 2 \cdot 10^5).

第一行包含两个整数 nn 和 qq(1≤n,q≤2⋅1051 \le n, q \le 2 \cdot 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤2⋅1051 \le a_i \le 2 \cdot 10^5),表示数组 aa 在修改前的元素。

接下来的 qq 行每行包含一个查询,格式如下:每行包含两个整数 ii 和 xx(1≤i≤n1 \le i \le n,1≤x≤2⋅1051 \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.

输出 qq 行:每处理完一个查询后,在单独一行输出所有元素的最大公约数(GCD)对 109+710^9+7 取模的结果。

输入输出样例

  • 输入#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.

第一次查询后,数组变为 [12,6,8,12][12, 6, 8, 12],gcd⁡(12,6,8,12)=2\operatorname{gcd}(12, 6, 8, 12) = 2。

第二次查询后,数组变为 [12,18,8,12][12, 18, 8, 12],gcd⁡(12,18,8,12)=2\operatorname{gcd}(12, 18, 8, 12) = 2。

第三次查询后,数组变为 [12,18,24,12][12, 18, 24, 12],gcd⁡(12,18,24,12)=6\operatorname{gcd}(12, 18, 24, 12) = 6。

此处 gcd⁡\operatorname{gcd} 函数表示最大公约数。

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

首页