No.3521 Slope of the Tangent Line
Problem Statement
This is a reactive problem (your program must run interactively with the judge's program).
First, a non-negative integer $D$ is given.
Tangent-Loving Bot is a bot that loves tangent lines.
Tangent-Loving Bot secretly holds a non-zero polynomial $f(x)$ of degree $D$ with non-negative integer coefficients. Let $C$ be the curve in the $xy$-plane defined by the equation $y = f(x)$.
Tangent-Loving Bot wants to know $1$ integer that can be the slope of a tangent line of the curve $C$.
So, you perform the following exchange (hereafter called a query) any number of times between $0$ and $10$, inclusive.
- First, you choose $1$ integer $n$ satisfying the condition $0 \leq n \leq 10^2$ and ask for the value $f(n)$ of $f(x)$ at $n$.
- Then, Tangent-Loving Bot answers with $f(n)$.
After that, determine whether there exists an integer that can be the slope $f'(x_0)$ of the tangent line at the point $(x_0,f(x_0))$ of the curve $C$ as the non-negative real number $x_0$ varies under the condition $0 \leq x_0 \leq 10^2$, and if one exists, find $1$ such integer.
Input and Output
First, $D$ is given from standard input on $1$ line.
$D$
After that, make queries any number of times between $0$ and $10$, inclusive. Each query is made using standard input and output in the following format:
- First, output
?and an integer $n$ satisfying the condition $0 \leq n \leq 10^2$, separated by a half-width space, on $1$ line. - Then, the value of $f(n)$ is given on $1$ line.
? $n$
$f(n)$
Next, output your answer to this problem to standard output in the following format:
- If there exists an integer that can be the slope $f'(x_0)$ of the tangent line at the point $(x_0,f(x_0))$ of the curve $C$ as the non-negative real number $x_0$ varies under the condition $0 \leq x_0 \leq 10^2$, let $c$ be one example of such a value, and output
!and $c$, separated by a half-width space, on $1$ line.
! $c$
! and NaN on $1$ line.! NaN
Finally, output a newline.
Constraints
Although not given in the input, $f(x)$ satisfies the following:
- $f(x)$ is fixed before all queries as a non-zero polynomial of degree $D$ with non-negative integer coefficients; that is, it does not change before or after a query.
- For any non-negative integer $d$ not greater than $D$, the coefficient $f_d$ of the degree-$d$ term of $f(x)$ is an integer satisfying the following.
- If $d < D$, then $0 \leq f_d < 10^2$.
- If $d = D$, then $0 < f_d < 10^2$.
The input satisfies the following constraints:
- $D$ is an integer satisfying $0 \leq D < 10^2$.
- For any integer $n$ satisfying the condition $0 \leq n \leq 10^2$, the input $f(n)$, which is the response when asking for the value of $f(x)$ at $n$, is an integer satisfying $0 \leq f(n) < 10^{2(D+1)}$.
Note that when $D = 99$, the upper bound of $f(10^2)$ is $10^{200} - 1$, which does not fit in a 64-bit integer.
Notes
If you are not familiar with reactive problems, please also refer to the summary on reactive problems.
In this problem, the judge result is not guaranteed for submissions that do not follow the instructions below:
- Strictly follow the specified output format. For example, do not add extra spaces.
- Each time you output, add a newline at the end and flush standard output.
- Terminate your program immediately after outputting your answer to this problem.
Sample
The following is an example of input and output in the case where $f(x) = 1 + x + 2x^2$.
| Input | Output | Explanation |
|---|---|---|
2 |
$D = 2$ was given as input. This establishes that $f(x)$ has degree $2$. | |
? 0 |
You asked for the value of $f(0)$. | |
1 |
Tangent-Loving Bot answered that $f(0) = 1 + 0 + 2 \cdot 0^2$ is $1$. | |
? 1 |
You asked for the value of $f(1)$. | |
4 |
Tangent-Loving Bot answered that $f(1) = 1 + 1 + 2 \cdot 1^2$ is $4$. | |
? 2 |
You asked for the value of $f(2)$. | |
11 |
Tangent-Loving Bot answered that $f(2) = 1 + 2 + 2 \cdot 2^2$ is $11$. | |
? 3 |
You asked for the value of $f(3)$. | |
22 |
Tangent-Loving Bot answered that $f(3) = 1 + 3 + 2 \cdot 3^2$ is $22$. | |
! 2 |
You answered $2$ as an integer that can be the slope $f'(x_0)$ of the tangent line at the point $(x_0,f(x_0))$ of the curve $C$ as the non-negative real number $x_0$ varies under the condition $0 \leq x_0 \leq 10^2$. Indeed, $f'(x) = 4x+1$, and for example, setting $x_0 = 4^{-1}$ gives $0 \leq x_0 \leq 10^2$ and $f'(x_0) = 2$. |
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
t9unkubj