CF1114F.Please, another Queries on Array?

提高+/省选-

通过率:0%

时间限制:5.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array a1,a2,…,ana_1, a_2, \ldots, a_n.

You need to perform qq queries of the following two types:

  1. "MULTIPLY l r x" — for every ii (l≤i≤rl \le i \le r) multiply aia_i by xx.
  2. "TOTIENT l r" — print φ(∏i=lrai)\varphi(\prod \limits_{i=l}^{r} a_i) taken modulo 109+710^9+7, where φ\varphi denotes Euler's totient function.

The Euler's totient function of a positive integer nn (denoted as φ(n)\varphi(n)) is the number of integers xx (1≤x≤n1 \le x \le n) such that gcd⁡(n,x)=1\gcd(n,x) = 1.

给你一个数组 a1,a2,…,ana_1, a_2, \ldots, a_n。

你需要执行 qq 次如下两种类型的查询:

  1. “MULTIPLY l r x”——对每个 ii(满足 l≤i≤rl \le i \le r),将 aia_i 乘以 xx;
  2. “TOTIENT l r”——输出 φ(∏i=lrai)\varphi(\prod \limits_{i=l}^{r} a_i) 对 109+710^9+7 取模的结果,其中 φ\varphi 表示欧拉函数(Euler's totient function)。

正整数 nn 的欧拉函数(记作 φ(n)\varphi(n))定义为满足 1≤x≤n1 \le x \le n 且 gcd⁡(n,x)=1\gcd(n,x) = 1 的整数 xx 的个数。

输入格式

The first line contains two integers nn and qq (1≤n≤4⋅1051 \le n \le 4 \cdot 10^5, 1≤q≤2⋅1051 \le q \le 2 \cdot 10^5) — the number of elements in array aa and the number of queries.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤3001 \le a_i \le 300) — the elements of array aa.

Then qq lines follow, describing queries in the format given in the statement.

  1. "MULTIPLY l r x" (1≤l≤r≤n1 \le l \le r \le n, 1≤x≤3001 \le x \le 300) — denotes a multiplication query.
  2. "TOTIENT l r" (1≤l≤r≤n1 \le l \le r \le n) — denotes a query on the value of Euler's totient function.

It is guaranteed that there is at least one "TOTIENT" query.

第一行包含两个整数 nn 和 qq(1≤n≤4⋅1051 \le n \le 4 \cdot 10^5,1≤q≤2⋅1051 \le q \le 2 \cdot 10^5)——分别表示数组 aa 的元素个数和查询次数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤3001 \le a_i \le 300)——表示数组 aa 的元素。

接下来是 qq 行,每行描述一个如题面所述格式的查询:

  1. “MULTIPLY l r x”(1≤l≤r≤n1 \le l \le r \le n,1≤x≤3001 \le x \le 300)——表示一次乘法操作。
  2. “TOTIENT l r”(1≤l≤r≤n1 \le l \le r \le n)——表示一次关于欧拉函数 φ\varphi 的查询。

保证至少存在一个 “TOTIENT” 查询。

输出格式

For each "TOTIENT" query, print the answer to it.

对于每个 “TOTIENT” 查询,输出其答案。

输入输出样例

  • 输入#1

    4 4
    5 9 1 2
    TOTIENT 3 3
    TOTIENT 3 4
    MULTIPLY 4 4 3
    TOTIENT 4 4

    输出#1

    1
    1
    2

说明/提示

In the first example, φ(1)=1\varphi(1) = 1 for the first query, φ(2)=1\varphi(2) = 1 for the second query and φ(6)=2\varphi(6) = 2 for the third one.

在第一个例子中,第一次查询的 φ(1)=1\varphi(1) = 1,第二次查询的 φ(2)=1\varphi(2) = 1,第三次查询的 φ(6)=2\varphi(6) = 2。

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

首页