

Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 150 点
問題文
正整数 A と正の奇数 B が与えられます。
実数 \dfrac AB との差が最小となる整数を出力してください。
ただし、制約のもとでそのような整数がただ一つ存在することが証明できます。
制約
- 1\leq A\leq407
- 1\leq B\leq407
- B は奇数
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
A B
出力
\dfrac AB との差が最小となる整数を出力せよ。
入力例 1
4 7
出力例 1
1
\dfrac AB=\dfrac47=0.5714\ldots です。 \dfrac AB と 1 との差は \dfrac37=0.4285\ldots で、これより差が小さい整数はありません。
よって、1
を出力してください。
入力例 2
407 29
出力例 2
14
\dfrac AB=\dfrac{407}{29}=14.0344\ldots です。 \dfrac AB と 14 との差は \dfrac1{29}=0.0344\ldots で、これより差が小さい整数はありません。
よって、14
を出力してください。
入力例 3
22 11
出力例 3
2
\dfrac AB が整数である場合もあります。
Score : 150 points
Problem Statement
You are given a positive integer A and a positive odd integer B.
Output the integer whose difference from the real number \dfrac AB is the smallest.
It can be proved that, under the constraints, such an integer is unique.
Constraints
- 1 \le A \le 407
- 1 \le B \le 407
- B is odd.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
A B
Output
Output the integer that minimizes the difference from \dfrac AB.
Sample Input 1
4 7
Sample Output 1
1
We have \dfrac AB = \dfrac47 = 0.5714\ldots. The difference between \dfrac AB and 1 is \dfrac37 = 0.4285\ldots, and no integer has a smaller difference.
Thus, print 1
.
Sample Input 2
407 29
Sample Output 2
14
We have \dfrac AB = \dfrac{407}{29} = 14.0344\ldots. The difference between \dfrac AB and 14 is \dfrac1{29} = 0.0344\ldots, and no integer has a smaller difference.
Thus, print 14
.
Sample Input 3
22 11
Sample Output 3
2
\dfrac AB may itself be an integer.