### main

loop do
  pn, n = gets.split.map(&:to_i)
  break if (pn | n) == 0

  rpn0 = Math.sqrt(pn).to_i
  rpn1 = rpn0 + 1
  
  uv = Rational(rpn0, 1)
  xy = Rational(rpn1, 1)

  
  for den in (1..n)
    pnden2 = pn * den * den

    num0 = (uv * den).ceil
    break if num0 > n

    num1 = (xy * den).floor
    num1 = n if num1 > n

    for num in (num0..num1)
      if num * num < pnden2
        r = Rational(num, den)
        uv = r if uv < r
      else
        r = Rational(num, den)
        xy = r if xy > r
      end
    end
  end

  puts [xy, uv].join(' ')
end