#GL0000380. Truy vấn hàm phi trên tích đoạn (Please, another Queries on Array?)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 . Process operations in order:
MULTIPLY l r x: multiply every element from through by . The update persists.TOTIENT l r: let and output , where counts integers satisfying and .
The array elements can become enormous; do not reduce them modulo before applying the totient function. The modulus applies to the answer only.
Input
The first line contains . The second line contains the initial elements. Each of the next lines contains either MULTIPLY l r x or TOTIENT l r. Indices are 1-based, with . 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): , , , .
-
Subtask 2 (30 points): , , , .
-
Subtask 3 (50 points): , , , .
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 , so . The second product is , so its totient is . Next, the last element changes from to ; because only and are coprime to among .
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 , so the answer is . After the updates, the array is , the product is , and .