Logo
(追記) (追記ここまで)

5804번 - RealPhobia 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB195594129.496%

문제

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 A/B, where B > 2 and 0 < A < B, your program needs to identify a rational number C/D such that:

  1. 0 < C < D < B, and
  2. the error |A/B - C/D| is the minimum over all possible values of C and D, and
  3. D is the smallest such positive integer.

입력

The input starts with an integer K (1 < K < 1000) that represents the number of cases on a line by itself. Each of the following K lines describes one of the cases and consists of a fraction formatted as two integers, A and B, separated by “/” such that:

  1. B is a 32 bit integer strictly greater than 2, and
  2. 0 < A < B

출력

For each case, the output consists of a fraction on a line by itself. The fraction should be formatted as two integers separated by “/”.

제한

예제 입력 1

3
1/4
2/3
13/21

예제 출력 1

1/3
1/2
8/13

힌트

출처

ICPC > Regionals > South Pacific > South Pacific Region > 2011 ACM South Pacific Programming Contest E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /