Problem9153--ABC333 —— G - Nearest Fraction

9153: ABC333 —— G - Nearest Fraction

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 512 MiB

Description

You are given a positive real number $r$ less than $1$, and a positive integer $N$.

Among the pair of integers $(p,q)$ such that $0\leq p\leq q\leq N$ and $\gcd(p,q)=1$, find the one that minimizes $\left\vert r-\dfrac pq\right\vert$.

If multiple such pairs $(p,q)$ exist, print the one with the smallest value of $\dfrac pq$.

Input

The input is given from Standard Input in the following format:

```
$r$
$N$
```

Output

For the pair $(p,q)$ that satisfies the conditions in the problem statement, print $p$ and $q$ in this order, separated by a space, in a single line.

Constraints

-   $0\lt r\lt 1$
-   $r$ is given as a real number with at most $18$ decimal places.
-   $1\leq N\leq 10^{10}$
-   $N$ is an integer.

Sample 1 Input

0.333
33

Sample 1 Output

1 3
$∣0.333−\frac{1}{3}∣=\frac{1}{3000}$. There is no 0≤p≤q≤33,gcd(p,q)=1 such that $∣0.333−\frac{p}{q}∣<\frac{1}{3000}$, so print 1 3.

Sample 2 Input

0.45
5

Sample 2 Output

2 5
$∣0.45−\frac{1}{2}∣=∣0.45−\frac{2}{5}∣=\frac{1}{20}$. There is no 0≤p≤q≤5,gcd(p,q)=1 such that $∣0.45−\frac{p}{q}∣<\frac{1}{20}$, and we have $\frac{1}{2}>\frac{2}{5}$, so print 2 5.

Sample 3 Input

0.314159265358979323
10000

Sample 3 Output

71 226
$∣0.314159265358979323−\frac{71}{226}∣=\frac{3014435336501}{113000000000000000000}$.

0.007735339533561113
7203576162

34928144 4515398949

HINT

相同题目:ABC333

Source/Category