#P2485. [SDOI2011] 计算器

    ID: 1499 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2011各省省选山东O2优化素数判断,质数,筛法最大公约数,gcd逆元

[SDOI2011] 计算器

Description

You are asked to design a calculator to complete 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 xyz(modp)xy \equiv z \pmod p.
  3. Given y,z,py, z, p, compute the smallest non-negative integer xx such that yxz(modp)y^x \equiv z \pmod p.

Do your best to win the prize!

Input Format

The input contains multiple test cases.

The first line contains two positive integers T,KT, K, denoting the number of test cases and the query type, respectively (for all testdata within a single test point, the query type is the same).

Each of the following TT lines contains three positive integers y,z,py, z, p, describing one query.

Output Format

The output contains TT lines.

For each query, output one line with the answer.

For query types 22 and 33, if no solution exists, output Orz, I cannot find x!.

3 1
2 1 3
2 2 3
2 3 3

2
1
2

3 2
2 1 3
2 2 3
2 3 3

2
1
0

4 3
2 1 3
2 2 3
2 3 3
2 4 3

0
1
Orz, I cannot find x!
0

Hint

Test points are divided into three categories. The proportion of each category among all test points is as follows:

K=K= Proportion of test points
11 20%20\%
22 35%35\%
33 45%45\%

All testdata satisfy: 1y,z,p1091 \leq y, z, p \leq 10^9, pp is prime, and 1T101 \leq T \leq 10.

Translated by ChatGPT 5