PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000380. Truy vấn hàm phi trên tích đoạn (Please, another Queries on Array?)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Truy vấn hàm phi trên tích đoạn (Please, another Queries on Array?)

Please, another Queries on Array?

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array of positive integers a1,a2,…,ana_1,a_2,\ldots,a_n. Process qq operations in order:

  • MULTIPLY l r x: multiply every element from ala_l through ara_r by xx. The update persists.
  • TOTIENT l r: let P=∏i=lraiP=\prod_{i=l}^{r}a_i and output φ(P) mod (109+7)\varphi(P)\bmod (10^9+7), where φ(P)\varphi(P) counts integers zz satisfying 1≤z≤P1\le z\le P and gcd⁡(z,P)=1\gcd(z,P)=1.

The array elements can become enormous; do not reduce them modulo 109+710^9+7 before applying the totient function. The modulus applies to the answer only.

Input

The first line contains n,qn,q. The second line contains the nn initial elements. Each of the next qq lines contains either MULTIPLY l r x or TOTIENT l r. Indices are 1-based, with l≤rl\le r. At least one TOTIENT query occurs.

Output

Output one integer for each TOTIENT query, in the same order. Updates produce no output.

Subtasks

  • Subtask 1 (20 points): 1≤n≤2 0001\le n\le 2\,000, 1≤q≤2 0001\le q\le 2\,000, 1≤ai,x≤3001\le a_i,x\le300, 1≤l≤r≤n1\le l\le r\le n.

  • Subtask 2 (30 points): 1≤n≤50 0001\le n\le 50\,000, 1≤q≤50 0001\le q\le 50\,000, 1≤ai,x≤3001\le a_i,x\le300, 1≤l≤r≤n1\le l\le r\le n.

  • Subtask 3 (50 points): 1≤n≤400 0001\le n\le 400\,000, 1≤q≤200 0001\le q\le 200\,000, 1≤ai,x≤3001\le a_i,x\le300, 1≤l≤r≤n1\le l\le r\le n.

Every subtask guarantees at least one TOTIENT query.

Examples

Example 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

Explanation

The first queried product is 11, so φ(1)=1\varphi(1)=1. The second product is 1⋅2=21\cdot2=2, so its totient is 11. Next, the last element changes from 22 to 66; φ(6)=2\varphi(6)=2 because only 11 and 55 are coprime to 66 among 1,…,61,\ldots,6.

Example 2

Input

2 4
2 3
TOTIENT 1 2
MULTIPLY 1 1 2
MULTIPLY 2 2 2
TOTIENT 1 2

Output

2
8

Explanation

Initially the product is 66, so the answer is 22. After the updates, the array is [4,6][4,6], the product is 2424, and φ(24)=8\varphi(24)=8.