Note: this problem requires Euler's theorem, which by the IOI 2023 Syllabus is Outside of Focus. Necessary information regarding that theorem and modular arithemetic are given in the paragraph below.
You a given a sequence . You are also given a constant . You need to support the following operations:
0 l r
: For each in , update to .1 l r
: find the sum of the subinterval . That is to say, you need to output Since the answer might be large, you only need to output the result modulo .
Properties of numbers modulo
The greatest common divisor of two positive integers and is the maximum integer that divides both and . and are coprime if their greatest common divisor is .
Let denote the number of integers in that are coprime to . You can compute using the following relation: Here, the product is over the distinct prime numbers dividing .
Alternatively, suppose the prime factorization of is given by where , then
The Extended Euler's Theorem asserts the following relation for .
- If , then nothing interesting can be said: .
- If , we have .
Note that this holds even when and are not coprime to each other.
Input Specification
The first line of the input contains four integers . stands for the length of the sequence, is the number of operations, is the modulus, and is the base.
The next line contains integers denoting the inital sequence .
In the following lines, each line consists of a query using the format specified above.
Output Specification
For each query of the form 1 l r
, output a line with an integer denoting the sum ().
Sample Input
4 5 20 3
2 0 2 3
0 1 4
1 3 4
0 1 4
1 1 3
1 2 4
Sample Output
16
9
13
Explanation of Sample 1
Initially, .
After the first operation, .
After the third operation, . Thus, .
Sample Input 2
3 4 3 2
0 1 0
0 1 3
0 1 3
0 1 3
1 1 3
Sample Output 2
0
Explanation of Sample 2
Initially . The three operations on it takes it to , , and respectively.
Constraints
For all test cases, , . For all , initially . For all queries, we have .
- Subtask 1 (10 points): .
- Subtask 2 (20 points): . Depends on Subtask 1.
- Subtask 3 (10 points): , for all queries of form
0 l r
, , and each array element will only be modified at most once. Notice we only guarantee we modify one value at a time, we might still ask for the sum over an interval. - Subtask 4 (10 points): . Depends on Subtask 1,3.
- Subtask 5 (20 points): . Depends on Subtask 1,3,4.
- Subtask 6 (30 points): No additional constraints. Depends on all previous subtasks.
- Warning: is not always a prime.
Comments