Unlucky 89

Average the circumferences of all integer right triangles whose hypotenuse is k*sqrt(89) with k up to n, printed as exact mixed numbers in an ASCII box.

Hard9Number theoryMathCombinatoricsImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

Amir thinks 89 is an unlucky number for him. He still wanted to know more about it, so he looked it up and learned that 89 is the 24th prime and also a Fibonacci number.

Lately Amir studies right triangles. He calls a right triangle unlucky if both legs have integer length and the hypotenuse is an integer multiple of 89\sqrt{89}. For example, the right triangle with sides (5,8,89)(5, 8, \sqrt{89}) is unlucky. So are (4,47,589)(4, 47, 5\sqrt{89}), (17,44,589)(17, 44, 5\sqrt{89}) and (10,16,289)(10, 16, 2\sqrt{89}).

The energy of an unlucky triangle is its hypotenuse divided by 89\sqrt{89}. If the hypotenuse is k89k\sqrt{89}, the energy is kk. The energy of (5,8,89)(5, 8, \sqrt{89}) is 11, and the energy of (71,100,1389)(71, 100, 13\sqrt{89}) is 1313.

Take every unlucky triangle whose energy is at most nn and compute the average circumference. The circumference is the sum of the three sides. Triangles of the same shape and size are counted once. Amir wants an exact answer.

Input

The input holds several test cases. Each line contains one integer nn, and the cases continue until the end of the input. (1n1081 \le n \le 10^8, and the sum of all nn in the input is less than 2×1082 \times 10^8)

Output

Print five lines for each test case. The average circumference is always of the form A+B89A + B\sqrt{89} with rational AA and BB. Write AA and BB as mixed numbers and place them in a box of this shape.

***************************************************
*          Numerator1             Numerator2    __*
*Integer1------------ + Integer2------------ x V89*
*        Denominator1           Denominator2      *
***************************************************
  • Both mixed numbers must be irreducible.
  • When the numerator is 0, drop the proper fraction and print only the integer part.
  • When Numerator2 is 0 and Integer2 is 1, drop the "1 x " part as well.
  • The fraction bar is a run of '-' as long as the denominator. The numerator is right aligned above the bar, and the denominator sits directly below it.
  • The radical is written 'V89', with one '_' in each of the two cells directly above '89'.
  • The width of the box matches the length of the middle line. The first and last lines consist only of '', and the three middle lines start and end with ''.
  • Apart from digits, the only characters used are '*' (ascii 42), ' ' (32), '_' (95), '-' (45), 'x' (120) and 'V' (86).
  • Print a blank line after each test case.

Hint

For n=108n = 10^8 there are 637149947637149947 unlucky triangles of different shapes and sizes.

Consider n=8n = 8. The unlucky triangles with energy at most 8 are (5,8,89)(5, 8, \sqrt{89}), (10,16,289)(10, 16, 2\sqrt{89}), (15,24,389)(15, 24, 3\sqrt{89}), (20,32,489)(20, 32, 4\sqrt{89}), (4,47,589)(4, 47, 5\sqrt{89}), (17,44,589)(17, 44, 5\sqrt{89}), (25,40,589)(25, 40, 5\sqrt{89}), (30,48,689)(30, 48, 6\sqrt{89}), (35,56,789)(35, 56, 7\sqrt{89}) and (40,64,889)(40, 64, 8\sqrt{89}), ten in all. Their circumferences add up to 580+4689580 + 46\sqrt{89}, so the average is (580+4689)/10(580 + 46\sqrt{89}) / 10.