CF281B.Nearest Fraction

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction whose denominator is no more than n.

Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value is as minimal as possible.

If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.

给你三个正整数 xx、yy、nn。你的任务是找出分母不超过 nn 的、最接近分数 xy\frac{x}{y} 的分数。

形式化地说,你需要找到一对整数 aa、bb(满足 1≤b≤n1 \leq b \leq n;0≤a0 \leq a),使得值 ∣ab−xy∣\left|\frac{a}{b} - \frac{x}{y}\right| 尽可能小。

如果存在多个“最接近”的分数,则选择分母最小的那个;如果存在多个分母最小的“最接近”分数,则选择其中分子最小的那个。

输入格式

A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).

一行包含三个整数 xx、yy、nn(1 ≤ x, y, n ≤ 1051 \le x, y, n \le 10^5)。

输出格式

Print the required fraction in the format "a/b" (without quotes).

以“a/b”(不含引号)的格式输出所要求的分数。

输入输出样例

  • 输入#1

    3 7 6

    输出#1

    2/5
  • 输入#2

    7 2 4

    输出#2

    7/2

输入解题思路,AI测评打分。不知道怎么写?

首页