#P10699. [SNCPC2024] 猜质数 I

    ID: 12143 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2024交互题Special JudgeO2优化陕西XCPC

[SNCPC2024] 猜质数 I

Problem Description

This is an interactive problem.

MCPlayer542 has a mysterious odd prime pp, but he does not want you to know what it is.

He plans to use a function f(x)f(x) to encrypt his number. The value of f(x)f(x) is the sum of the decimal digits of xx. For example, f(5)=5f(5)=5, f(542)=5+4+2=11f(542)=5+4+2=11, and f(1024)=1+0+2+4=7f(1024)=1+0+2+4=7.

However, since you are too smart, he thought about it and decided to change the encryption function to:

g(x)=f(f(f(f(f(f(f(f(f(f(x))))))))))g(x)=f(f(f(f(f(f(f(f(f(f(x))))))))))

That is, apply f(x)f(x) continuously 1010 times, and replace the pp in his hand with q=pkq=p^k.

Now he is going to give you nn integers g(qa1), g(qa2), , g(qan)g(q^{a_1}),\ g(q^{a_2}),\ \ldots,\ g(q^{a_n}), and he wants you to tell him what

$$q^{a_1}\bmod (m\cdot a_1),\ q^{a_2}\bmod (m\cdot a_2),\ \ldots,\ q^{a_n}\bmod (m\cdot a_n)$$

are, respectively. He thinks you definitely cannot guess it, so he decides to let you choose mm and a1, a2, , ana_1,\ a_2,\ \ldots,\ a_n yourself. Can you complete this task?

Note: The range of mm has special constraints.

Input Format

The input contains multiple test cases. The first line contains an integer tt (1t5001\le t\le 500), indicating the number of test cases. The interactive process for each test case is described below.

In each test case, the first line contains two integers nn and kk (1n50, 1k1091\le n\le 50, \ 1\le k\le 10^9), separated by a single space, with meanings as described in the statement.

Then, for each interaction, output one integer aia_i per line (1ai1018,ai1\le a_i\le 10^{18},a_i are pairwise distinct), indicating the exponent of qq you want to query.

After making a query, you should read an integer, which is g(qai)g(q^{a_i}).

After finishing nn rounds of interaction, you need to output one integer mm in one line (m35,1mai1018m\ge 35,1\le m\cdot a_i\le 10^{18}), then output nn numbers in the next line: $q^{a_1}\bmod (m\cdot a_1), \ q^{a_2}\bmod (m\cdot a_2), \ \ldots, \ q^{a_n}\bmod (m\cdot a_n)$, separated by single spaces, as the answer.

You must perform exactly nn rounds of interaction, then output the answer and terminate the program, otherwise you may get unpredictable results.

Note that at the end of each output in your program (that is, each time you output aia_i for an interaction, and when you finally output mm and the answers), you need to print a newline and flush the output buffer. Otherwise, you will get Idleness Limit Exceeded\text{Idleness Limit Exceeded}.

  • In C: fflush(stdout)\text{fflush(stdout)};
  • In C++: cout.flush()\text{cout.flush()};
  • In Java: System.out.flush()\text{System.out.flush()};
  • In Python: stdout.flush()\text{stdout.flush()};

to flush the output buffer.

It is guaranteed that the odd prime pp (2<p10182<p\le 10^{18}) in each test case is fixed before the interaction starts, and will not change with your input.

If your final output is correct, you will get Accepted\text{Accepted}.

If your mm or aia_i do not satisfy the constraints, or your final output is incorrect, you will get Wrong Answer\text{Wrong Answer}.

In addition, other verdicts will still be returned during judging according to the usual situations.

2
3 1

3

9

9


3 2

4

4

4





1

2

3

100
3 9 27

1

7

49

49
0 0 0

Hint

In the first test case, the odd prime p=3p=3 in MCPlayer542's hand, so q=pk=3q=p^k=3.

We choose the array a={1, 2, 3}a=\{1,\ 2,\ 3\}, and obtain g(31)=3, g(32)=9, g(33)=9g(3^1)=3, \ g(3^2)=9, \ g(3^3)=9 in order.

Then we guess p=3p=3 and choose m=100m=100, so we output $3^1\bmod (100\times 1)=3, \ 3^2\bmod (100\times 2)=9, \ 3^3\bmod (100\times 3)=27$.

In the second test case, the odd prime p=7p=7 in MCPlayer542's hand, so q=pk=49q=p^k=49.

We choose the array a={1, 7, 49}a=\{1,\ 7,\ 49\}, and obtain g(491)=4, g(497)=4, g(4949)=4g(49^1)=4,\ g(49^7)=4,\ g(49^{49})=4 in order.

Then we keenly notice p=7p=7 and choose m=49m=49, so we output $49^1\bmod (49\times 1)=0, \ 49^7\bmod (49\times 7)=0, \ 49^{49}\bmod (49\times 49)=0$.

Note: The phrase “keenly notice” in the second test case is only used as an illustration of the interactive process, and does not guarantee that the above interaction can determine that p=7p=7.

Translated by ChatGPT 5