Unlucky 89
Time limit2sMemory limit512 MB
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.
- Level
Hard9 of 10
- Topics
- Number theory, Math, Combinatorics, Implementation
- Solved
- No attempts yet
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 . For example, the right triangle with sides is unlucky. So are , and .
The energy of an unlucky triangle is its hypotenuse divided by . If the hypotenuse is , the energy is . The energy of is , and the energy of is .
Take every unlucky triangle whose energy is at most 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 , and the cases continue until the end of the input. (, and the sum of all in the input is less than )
Output
Print five lines for each test case. The average circumference is always of the form with rational and . Write and 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 there are unlucky triangles of different shapes and sizes.
Consider . The unlucky triangles with energy at most 8 are , , , , , , , , and , ten in all. Their circumferences add up to , so the average is .