#P15427. Nobody Tells (Original Version)

    ID: 17449 远端评测题 4000ms 512MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>数论交互题Special JudgeO2优化Fibonacci 数列逆元

Nobody Tells (Original Version)

Background

Problem Description

Please note the differences between this problem and P15425 Nobody Tells — this problem has stricter constraints on queries.


This is an interactive problem.

Coola has two numbers p,qp, q, and a prime number MM. We generate a sequence {fi}\{f_i\} in the following way:

$$\begin{cases} f_{0}=1\\ f_{1}=p\\ f_{i}=(pf_{i-1}+qf_{i-2})\bmod M,&i>1 \end{cases}$$

The interactive judge will give you MM and a parameter LL. You can query the judge at most 33 times:

  • Provide an index L≤i<ML\le i\red{<M}, and the judge tells you the value of fif_i.

Your task is to guess the value of (p,q)(p, q) after at most 33 queries. In particular, you may guess two pairs of (p,q)(p, q) at the same time, see the interaction details.

Interaction Details

This problem contains multiple test cases.

In the first line of the input, the judge will give your program an integer TT, meaning the number of test cases in this test point.

For each test case:

The judge will have the (p,q)(p, q) for this test case. This also means the judge is non-adaptive.

In the first line, the judge inputs two integers M,LM, L to your program, meaning the modulus and the query restriction.

For each query, you need to output ? i, meaning querying the value of fif_i.

Under normal conditions, the judge will input an integer in [0,M)[0, M), which is the fif_i you queried.

If any of the following happens, the judge will immediately terminate the interaction and force your program to exit, and this test point will be judged as failed:

  • The number of queries exceeds 33.
  • ii is not in the range L≤i<ML\le i<M.

After you have guessed the possible (p,q)(p, q), you need to output ! p1 q1 p2 q2, meaning the two pairs of (p,q)(p, q) you guess are (p1,q1)(p_1, q_1) and (p2,q2)(p_2, q_2). This operation does not count toward the 33 queries. In particular, you must ensure that all four numbers are in the range [1,M)[1, M), otherwise the judge will immediately terminate the interaction and force your program to exit, and this test point will be judged as failed.

If at least one of the two answer pairs matches the value held by the judge, then this test case is passed; otherwise it is failed, and the judge will immediately terminate the interaction and force your program to exit.

If you pass all test cases in a test point, then this test point will be judged as passed.

1
5 1

3

1


? 1

? 2

! 3 2 1 1

Hint

Explanation of Sample #1

The data held by the judge is p=3,q=2,M=5,L=1p=3, q=2, M=5, L=1.

In the first interaction, your program queries the value of f1f_1 with ? 1\texttt{? 1}. Clearly f1=p=3f_1=p=3, so the judge inputs 33 to your program.

In the second interaction, your program queries the value of f2f_2 with ? 2\texttt{? 2}. We have f2=(pf1+qf0) mod 5=11 mod 5=1f_2=(pf_1+qf_0)\bmod 5=11\bmod 5=1. Therefore the judge inputs 11 to your program.

Since f2=(p2+q) mod 5f_2=(p^2+q)\bmod 5, and we know p=3p=3, we can solve q=2q=2. So you have determined the answer using two queries, and you can output ! 3 2 1 1\texttt{! 3 2 1 1}. Since the first pair of answers is correct, the second pair does not matter, so ! 3 2 4 3\texttt{! 3 2 4 3} is also a valid output. However, ! 3 2 1 5\texttt{! 3 2 1 5} or ! 3 2 0 4\texttt{! 3 2 0 4} are not, because you must ensure all four numbers are in the range [1,5)[1, 5).

Constraints

This problem uses bundled tests.

For 100%100\% of the data, 1≤T≤1051\le T\le 10^5. 106≤M≤10910^6\le M\le 10^9, and MM is guaranteed to be prime. 0≤L≤5×1050\le L\le 5\times 10^5.

The judge is non-adaptive, and 1≤p,q<M1\le p, q<M.

Subtask Special Property Score
1 L=1L=1 22
2 T≤500T\le 500 and L=15L=15 1010
3 M=106+3M=10^6+3 2020
4 T≤10T\le 10 and M≤5×106M\le 5\times 10^6
5 None 4848

Afterword

:::epigraph[——《Nobody Tells》] The lights that guide the way along the journey
You are one of them :::

Translated by ChatGPT 5