PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000063. Phân số kề một giá trị hữu tỉ (Rational Approximation)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Phân số kề một giá trị hữu tỉ (Rational Approximation)
Rational Approximation
Source: Library Checker
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integers N, x, y, let S contain all reduced positive fractions a/b with numerator and denominator at most N. Find the greatest element of S not exceeding x/y, and the smallest element of S not less than x/y. Use 0/1 for a nonexistent lower answer and 1/0 for a nonexistent upper answer. Comparisons must be mathematically exact.
Input
Three positive integers N x y.
Output
Four integers a b c d describing the lower and upper fractions.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Input
5 7 3
Output
2 1 5 2
Explanation
Among fractions with numerator and denominator at most 5, 2/1 is the largest at most 7/3 and 5/2 is the smallest at least 7/3.