#abc333g. G - Nearest Fraction
G - Nearest Fraction
Score : points
问题陈述
给定一个小于1的正实数 以及一个正整数 。
在满足条件 的整数对中,其中 并且 (即 和 互质),找出使得 最小的那一对。
如果存在多个满足条件的整数对 ,则输出其中 值最小的那个对。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a positive real number less than , and a positive integer .
Among the pair of integers such that and , find the one that minimizes .
If multiple such pairs exist, print the one with the smallest value of .
Constraints
- is given as a real number with at most decimal places.
- is an integer.
Input
The input is given from Standard Input in the following format:
Output
For the pair that satisfies the conditions in the problem statement, print and in this order, separated by a space, in a single line.
Sample Input 1
0.333
33
Sample Output 1
1 3
. There is no such that $\left\vert0.333-\dfrac pq\right\vert\lt\dfrac1{3000}$, so print 1 3
.
Sample Input 2
0.45
5
Sample Output 2
2 5
$\left\vert0.45-\dfrac12\right\vert=\left\vert0.45-\dfrac25\right\vert=\dfrac1{20}$. There is no such that , and we have , so print 2 5
.
Sample Input 3
0.314159265358979323
10000
Sample Output 3
71 226
$\left\vert0.314159265358979323-\dfrac{71}{226}\right\vert=\dfrac{3014435336501}{113000000000000000000}$.
Sample Input 4
0.007735339533561113
7203576162
Sample Output 4
34928144 4515398949
update @ 2024/3/10 01:20:36