Codeforces Round 959 sponsored by NEAR (Div. 1 + Div. 2)
H
Fortnite
Codeforces
3500
原题
← G→
翻译中…

This is an interactive problem!

翻译中…

Timofey is writing a competition called Capture the Flag (or CTF for short). He has one task left, which involves hacking a security system. The entire system is based on polynomial hashes$^{\text{∗}}$.

翻译中…

Timofey can input a string consisting of lowercase Latin letters into the system, and the system will return its polynomial hash. To hack the system, Timofey needs to find the polynomial hash parameters ($p$ and $m$) that the system uses.

翻译中…

Timofey doesn't have much time left, so he will only be able to make $3$ queries. Help him solve the task.

翻译中…

$^{\text{∗}}$ The polynomial hash of a string $s$, consisting of lowercase Latin letters of length $n$, based on $p$ and modulo $m$ is $(\mathrm{ord}(s_1) \cdot p ^ 0 + \mathrm{ord}(s_2) \cdot p ^ 1 + \mathrm{ord}(s_3) \cdot p ^ 2 + \ldots + \mathrm{ord}(s_n) \cdot p ^ {n - 1}) \bmod m$. Where $s_i$ denotes the $i$-th character of the string $s$, $\mathrm{ord}(\mathrm{chr})$ denotes the ordinal number of the character $\mathrm{chr}$ in the English alphabet, and $x \bmod m$ is the remainder of $x$ when divided by $m$.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^3$) — the number of test cases.

翻译中…

It is guaranteed that the $p$ and $m$ used by the system satisfy the conditions: $26 \lt p \leq 50$ and $p + 1 \lt m \leq 2 \cdot 10^9$.

翻译中…

Interaction

翻译中…

To make a query to the system, output ? $s$, where $s$ is a string of no more than $50$ characters in length, the hash of which you want to know. In response to this query, you will receive the polynomial hash of the string $s$.

翻译中…

To output the answer, output ! $p$ $m$, where $p$ is the base of the hash, and $m$ is the modulus. After that, immediately proceed to the next test case.

翻译中…

You have to make not more than $3$ queries ?, otherwise you will get verdict Wrong Answer.

翻译中…

After outputting a query, do not forget to output a newline and flush the output buffer. Otherwise, you will receive the verdict Idleness limit exceeded. To flush the buffer, use:

翻译中…
  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see the documentation for other languages.
翻译中…

Note

翻译中…

Answer for the first query is $(ord(a) \cdot 31^0 + ord(a) \cdot 31^1) \mod 59 = (1 + 1 \cdot 31) \mod 59 = 32$.

翻译中…

Answer for the second query is $(ord(y) \cdot 31^0 + ord(b) \cdot 31^1) \mod 59 = (25 + 2 \cdot 31) \mod 59 = 28$.

翻译中…

样例

Input #1
1

32

28
Output #1
? aa

? yb

! 31 59
InputCopy OutputCopy
题目信息
题号
1994H
时间限制
1 s
内存限制
256 MB
标签
组合数学
构造
博弈论
贪心
哈希
交互题
数学
数论
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。