eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Real Phobia

Real Phobia

Bert is a programmer with a real fear of floating point arithmetic. Bert has quite successfully used rational numbers to write his programs but he does not like it when the denominator grows large. Your task is to help Bert by writing a program that decreases the denominator of a rational number, whilst introducing the smallest error possible. For a rational number \textbf{A/B}, where \textbf{B} > \textbf{2} and \textbf{0} < \textbf{A} < \textbf{B}, your program needs to identify a rational number \textbf{C/D} such that: \begin{enumerate} \item \textbf{0} < \textbf{C} < \textbf{D} < \textbf{B}, and \item the error \textbf{|A/B - C/D|} is the minimum over all possible values of \textbf{C} and \textbf{D}, and \item \textbf{D} is the smallest such positive integer. \end{enumerate} \InputFile The input starts with an integer \textbf{K} (\textbf{1} ≤ \textbf{K} ≤ \textbf{1000}) that represents the number of cases on a line by itself. Each of the following \textbf{K} lines describes one of the cases and consists of a fraction formatted as two integers, \textbf{A} and \textbf{B}, separated by "\textbf{/}" such that: \begin{enumerate} \item \textbf{B} is a \textbf{32} bit integer strictly greater than \textbf{2}, and \item \textbf{0} < \textbf{A} < \textbf{B}. \end{enumerate} \OutputFile For each case, the output consists of a fraction on a line by itself. The fraction should be formatted as two integers separated by "\textbf{/}".
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
3 
1/4
2/3
13/21
Выходные данные #1
1/3
1/2
8/13
Источник The 2011 South Pacific Programming Contest