CF1114F.Please, another Queries on Array?
提高+/省选-
通过率:0%
时间限制:5.50s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a1,a2,…,an.
You need to perform q queries of the following two types:
- "MULTIPLY l r x" — for every i (l≤i≤r) multiply ai by x.
- "TOTIENT l r" — print φ(i=l∏rai) taken modulo 109+7, where φ denotes Euler's totient function.
The Euler's totient function of a positive integer n (denoted as φ(n)) is the number of integers x (1≤x≤n) such that gcd(n,x)=1.
给你一个数组 a1,a2,…,an。
你需要执行 q 次如下两种类型的查询:
- “MULTIPLY l r x”——对每个 i(满足 l≤i≤r),将 ai 乘以 x;
- “TOTIENT l r”——输出 φ(i=l∏rai) 对 109+7 取模的结果,其中 φ 表示欧拉函数(Euler's totient function)。
正整数 n 的欧拉函数(记作 φ(n))定义为满足 1≤x≤n 且 gcd(n,x)=1 的整数 x 的个数。
输入格式
The first line contains two integers n and q (1≤n≤4⋅105, 1≤q≤2⋅105) — the number of elements in array a and the number of queries.
The second line contains n integers a1,a2,…,an (1≤ai≤300) — the elements of array a.
Then q lines follow, describing queries in the format given in the statement.
- "MULTIPLY l r x" (1≤l≤r≤n, 1≤x≤300) — denotes a multiplication query.
- "TOTIENT l r" (1≤l≤r≤n) — denotes a query on the value of Euler's totient function.
It is guaranteed that there is at least one "TOTIENT" query.
第一行包含两个整数 n 和 q(1≤n≤4⋅105,1≤q≤2⋅105)——分别表示数组 a 的元素个数和查询次数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤300)——表示数组 a 的元素。
接下来是 q 行,每行描述一个如题面所述格式的查询:
- “MULTIPLY l r x”(1≤l≤r≤n,1≤x≤300)——表示一次乘法操作。
- “TOTIENT l r”(1≤l≤r≤n)——表示一次关于欧拉函数 φ 的查询。
保证至少存在一个 “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 for the first query, φ(2)=1 for the second query and φ(6)=2 for the third one.
在第一个例子中,第一次查询的 φ(1)=1,第二次查询的 φ(2)=1,第三次查询的 φ(6)=2。
输入解题思路,AI测评打分。不知道怎么写?