Easy Problem With Numbers


题目描述:

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

题解:

乘积然后还要模上一个数,还不是质数…
思路:不能够直接维护乘法,维护因子的个数,但是个数太多..
所以我们只维护模的那个数的因子,剩下的用正常的逆元来搞

重点:
代码:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值