编程介的小学生 2017-03-04 04:39 采纳率: 20.5%
浏览 1036
已采纳

Rational Irrationals

Rational numbers are numbers represented by ratios of two integers. For a prime number p, one of the elementary theorems in the number theory is that there is no rational number equal to the square root of p (abbreviated to SQRT(p)). Such numbers are called irrational numbers. It is also known that there are rational numbers arbitrarily close to SQRT(p).

Now, given a positive integer n, we define a set Qn of all rational numbers whose elements are represented by ratios of two positive integers both of which are less than or equal to n. For example, Q4 is a set of 11 rational numbers {1/1, 1/2, 1/3, 1/4, 2/1, 2/3, 3/1, 3/2, 3/4, 4/1, 4/3}. 2/2, 2/4, 3/3, 4/2 and 4/4 are not included here because they are equal to 1/1, 1/2, 1/1, 2/1 and 1/1, respectively.
Your job is to write a program that reads two integers p and n and reports two rational numbers x/y and u/v, where u/v < SQRT(p) < x/y and there are no other elements of Qn between u/v and x/y. When n is greater than SQRT(p), such a pair of rational numbers always exists.

Input

The input consists of lines each of which contains two positive integers, a prime number p and an integer n in the following format.

p n

They are separated by a space character. You can assume that p and n are less than 10000, and that n is greater than SQRT(p). The end of the input is indicated by a line consisting of two zeros.

Output

For each input line, your program should output a line consisting of the two rational numbers x/y and u/v (x/y > u/v) separated by a space character in the following format.

x/y u/v

They should be irreducible. For example, 6/14 and 15/3 are not accepted. They should be reduced to 3/7 and 5/1, respectively.

Sample Input

2 5
3 10
5 100
0 0

Sample Output

3/2 4/3
7/4 5/3
85/38 38/17

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-03-08 15:53
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?