Problem:
Problem A: 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 √p. Such numbers are called irrational numbers. It is also known that there are rational numbers arbitrarily close to √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 < √p < x / y and there are no other elements of Qn between u/v and x/y. When n is greater than √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 √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

Output for the Sample Input

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

Solution in C++ (judge verdict: Wrong Answer)

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <map>
using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)

typedef pair<int,int> P;

int main(){

  int n,pp;
  while(cin>>pp>>n&&!(n==0&&pp==0)){
    P lbp;
    double p=sqrt(pp);
    double lbval=-100000000;
    P ubp;
    double ubval=100000000.0;
    // ツ閉ェツ陛ェツづーツ個按津ィ
    for(int i = 1; i <= n; i++){
      // ub/iツつェpツづヲツづィツ渉ャツつウツつュツづ按づゥツ催妥・ツづ蛍bツづーツ探ツつキ
      int ub=n;
      int lb=-1;
      while(ub-lb>1){
	int med=(ub+lb)/2;
	double val=1.0*med/i;
	if(p>val)
	  lb=med;
	else
	  ub=med;
      }
      if(!EQ(1.0*lb/i,p)&&((1.0*lb/i)<p)
	 &&(lbval<1.0*lb/i)&&!EQ(lbval,1.0*lb/i)){
	lbval=1.0*lb/i;
	lbp=P(lb,i);
      }
      // ub/iツつェpツづヲツづィツ妥・ツつォツつュツづ按づゥツ催渉ャツづ蛍bツづーツ探ツつキ
      ub=n;
      lb=-1;
      while(ub-lb>1){
	int med=(ub+lb)/2;
	double val=1.0*med/i;
	if(p<val)
	  ub=med;
	else
	  lb=med;
      }
      if(!EQ((1.0*ub/i),p)&&((1.0*ub/i)>p)
	 &&(ubval>1.0*ub/i)
	 &&!EQ(ubval,1.0*ub/i)){
	ubval=1.0*ub/i;
	ubp=P(ub,i);
      }
    }
    // ツ姪アツ閉ェ
    for(int j = 2; j <= min(ubp.first,ubp.second); j++){
      if(ubp.first%j==0&&ubp.second%j==0){
    	ubp.first/=j;ubp.second/=j;
	j--;
      }
    }
    for(int j = 2; j <= min(lbp.first,lbp.second); j++){
      if(lbp.first%j==0&&lbp.second%j==0){
    	lbp.first/=j;lbp.second/=j;
	j--;
      }
    }
    cout<<ubp.first<<"/"<<ubp.second<<" ";
    cout<<lbp.first<<"/"<<lbp.second<<endl;
  }
  return 0;
}