Number theory

TimeLimit:2000MS  MemoryLimit:524MB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description
Given a integers x = 1, you have to apply Q (Q ≤ 100000) operations: Multiply, Divide.
Input

First line of the input file contains an integer T(0 < T ≤ 10) that indicates how many cases of inputs are there.

The description of each case is given below:

The first line contains two integers Q and M. The next Q lines contains the operations in ith line following form:

M yi: x = x * yi.

N di: x = x / ydi.

It’s ensure that di is different. That means you can divide yi only once after yi came up.

0 < yi ≤ 10^9, M ≤ 10^9

Output

For each operation, print an integer (one per line) x % M.

SampleInput
1
10 1000000000
M 2
D 1
M 2
M 10
D 3
D 4
M 6
M 7
M 12
D 7
SampleOutput
2
1
2
20
10
1
6
42
504
84
Submit
题目统计信息详细
总AC数29
通过人数22
尝试人数24
总提交量72
AC率30.56%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: