题目描述:
E. Easy Problem With Numbers
Time Limit: 5000ms
Memory Limit: 65535KB
64-bit integer IO format: %lld Java class name: Main
Submit Status PID: 24253
Give a sequence of N integers, you are required to deal with the following operations.
1 For each integer in the interval [L, R], change its value to previous value multiplying or dividing an integer x.
2 Output the remainder of the product of all the integers in interval [L, R] mod a particular modulus.
Input
First line of the input is a single integer T(1 <= T <= 15), indicating there are T test cases.
The first line of each test case contains two numbers N (1 <= N <= 10000) and M (1 <= M <= 10^9).
The second line contains N numbers, the initial values of A1, A2, …, AN(0 <= Ai <= 10^9).
The third line contains a single number Q(1 <= Q <= 10000).
Each of the next Q lines represents an operation.
“M L R x” means for each integer in the interval [L, R], changing its value to previous value multiplying an integer x, we guarantee that x is not exceeded 10^9 and non negative.
“D L R x” means for each integer in the interval [L, R], changing its value to previous value dividing an integer x, we guarantee that x is positive integer not exceeded 10^9 and all the integers in the interval [L, R] can be divided into x parts with no remainder.
“Q L R” means output the remainder of the product of the integer in interval [L, R] mod M.
For all the operations, we guarantee that L <= R and there is a blank line before each test case.
Output
For each test case, print “Case #t:” first, in which t is the number of the test case starting from 1.
Then for each “Q L R” operation, output a single num in each line as the input says.
Sample Input
1
5 6
10 2 6 9 10
5
Q 1 2
M 1 4 3
Q 1 5
D 1 3 2
Q 1 3
Sample Output
Case #1:
2
0
3
题解:
乘积然后还要模上一个数,还不是质数…
思路:不能够直接维护乘法,维护因子的个数,但是个数太多..
所以我们只维护模的那个数的因子,剩下的用正常的逆元来搞
重点:
代码: