No.1936 Rational Approximation
タグ : / 解いたユーザー数 79
作問者 :
noya2
/ テスター :
tatyam
Problem Statement
For any positive rational number $u$, there exists a unique pair of coprime positive integers $(p,q)$ such that $\displaystyle u = \frac{p}{q}$, so we denote such $(p,q)$ by $(\ p(u),q(u)\ )$.
You are given $2$ coprime integers $P,\ Q\ (2\le P\lt Q)$.
Among the pairs of rational numbers $(L,\ R)$ satisfying both of the following conditions, the one minimizing $R-L$ is unique, so we denote such $(L,\ R)$ by $(L_{\max},\ R_{\min})$.
- $1\le q(L),\ q(R)\lt Q$
- $\displaystyle 0\lt L\lt \frac{P}{Q}\lt R$
Find $p(L_{\max}) + q(L_{\max}) + p(R_{\min}) + q(R_{\min})$.
Constraints
Input
$P\ Q$
Output
Print the answer on $1$ line.
Sample
Sample 1
Input
2 3
Output
5
We have $\displaystyle L_{\max} = \frac{1}{2},\ R_{\min} = 1$.
Since $p(L_{\max}) = 1,\ q(L_{\max}) = 2,\ p(R_{\min}) = 1,\ q(R_{\min}) = 1$, print their sum, $5$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。