#Q216. 「一本通 6.4 例 6」计算器

    ID: 2298 Type: Default 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>SDOI2011扩展欧几里德算法快速幂Baby Step Giant Step一本通提高

「一本通 6.4 例 6」计算器

Description

Original source: SDOI 2011

You are asked to design a calculator to perform the following three tasks:

  1. Given y,z,py,z,p, compute the value of yzmodpy^z\bmod p;
  2. Given y,z,py,z,p, compute the smallest non-negative integer xx such that x×yz (modp )x\times y\equiv z\ (\bmod p\ );
  3. Given y,z,py,z,p, compute the smallest non-negative integer xx such that yxz (modp )y^x\equiv z\ (\bmod p\ ).

Input Format

The input contains multiple test cases.

The first line contains two positive integers T,KT,K representing the number of test cases and the query type (for all data within a test case, the query type is the same);
Each of the next TT lines contains three positive integers y,z,py,z,p, describing a query.

Output Format

For each query, output one line with the answer.

For query types 22 and 33, if there is no solution, output Orz, I cannot find x!. Note there is a space between the comma and I.

Sample 1

3 1
2 1 3
2 2 3
2 3 3

2
1
2

Sample 2

3 2
2 1 3
2 2 3
2 3 3

2
1
0

Data Range and Hints

For all data, 1y,z,p109,1T101\le y,z,p\le 10^9,1\le T\le 10, and it is guaranteed that pp is a prime number.