CF BUDDY
← Problems·

1114F · Please, another Queries on Array?

2400 · bitmasks, data structures, divide and conquer

Problem: 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 (lirl \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 (1xn1 \le x \le n) such that gcd(n,x)=1\gcd(n,x) = 1.

Input Format: The first line contains two integers nn and qq (1n41051 \le n \le 4 \cdot 10^5, 1q21051 \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 (1ai3001 \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" (1lrn1 \le l \le r \le n, 1x3001 \le x \le 300) — denotes a multiplication query.
  2. "TOTIENT l r" (1lrn1 \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.

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

Note: 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.

Sample Cases

Case 1

Input

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

Output

1
1
2

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback