問題一覧 > 教育的問題

No.3361 Lattice Points Between Two Roots

レベル : / AI推定難易度 : 600 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 33
作問者 : 👑 p-adic / テスター : 👑 loop0919
お気に入りにしたユーザー ProblemId : 12330 / 自分の提出
問題文最終更新日: 2025-10-19 10:49:12
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 488 小数誤差コンテスト (順位表) の他の問題:

Problem Statement

You are given $3$ integers $A, B, C$, where $A \neq 0$ and $B^2 - 4AC > 0$. In particular, the quadratic equation $A x^2 + B x + C = 0$ has $2$ distinct real roots, which are

$\displaystyle \frac{- B \pm \sqrt{B^2 - 4AC}}{2A} \\ $

as expressed above.

Let $\alpha, \beta$ denote the $2$ roots in ascending order. Find the number of integers $n$ satisfying $\alpha < n < \beta$.

Input

The input is given from standard input in $1$ line in the following format:

  • Line $1$ contains $A, B, C$ separated by single spaces.
$A$ $B$ $C$

Constraints

The input satisfies the following constraints:

  • $A$ is an integer satisfying $1 \leq |A| \leq 10^6$.
  • $B$ is an integer satisfying $|B| \leq 10^6$.
  • $C$ is an integer satisfying $|C| \leq 10^6$.
  • $B^2 - 4AC > 0$.

Output

Output the number of integers $n$ satisfying $\alpha < n < \beta$ in $1$ line.

Print a newline at the end.

Sample

Sample 1
Input
1 1 0
Output
0

Since $A x^2 + B x + C = x^2 + x = (x+1)x$, we have $\alpha = -1, \beta = 0$.

There is no integer $n$ satisfying $-1 < n < 0$.

Sample 2
Input
2 8 6
Output
1

Since $A x^2 + B x + C = 2 x^2 + 8 x + 6 = 2(x + 3)(x + 1)$, we have $\alpha = -3, \beta = -1$.

The only integer $n$ satisfying $-3 < n < -1$ is $-2$, so there is $1$ such integer.

Sample 3
Input
-1 -2 1
Output
3

Since $A x^2 + B x + C = -x^2 - 2 x + 1 = -(x + 1 + \sqrt{2})(x + 1 - \sqrt{2})$, we have $\alpha = -1 - \sqrt{2}, \beta = -1 + \sqrt{2}$.

Since $-2.42 < -1 - \sqrt{2} < -2.41$ and $0.41 < -1 + \sqrt{2} < 0.42$, the integers $n$ satisfying $-1 - \sqrt{2} < n < -1 + \sqrt{2}$ are $-2, -1, 0$, which is $3$ integers.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。