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 MBAmir 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. For example, the right triangle with sides (5,8,89) is unlucky. So are (4,47,589), (17,44,589) and (10,16,289).
The energy of an unlucky triangle is its hypotenuse divided by 89. If the hypotenuse is k89, the energy is k. The energy of (5,8,89) is 1, and the energy of (71,100,1389) is 13.
Take every unlucky triangle whose energy is at most n 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.
The input holds several test cases. Each line contains one integer n, and the cases continue until the end of the input. (1≤n≤108, and the sum of all n in the input is less than 2×108)
Print five lines for each test case. The average circumference is always of the form A+B89 with rational A and B. Write A and B as mixed numbers and place them in a box of this shape.
***************************************************
* Numerator1 Numerator2 __*
*Integer1------------ + Integer2------------ x V89*
* Denominator1 Denominator2 *
***************************************************
For n=108 there are 637149947 unlucky triangles of different shapes and sizes.
Consider n=8. The unlucky triangles with energy at most 8 are (5,8,89), (10,16,289), (15,24,389), (20,32,489), (4,47,589), (17,44,589), (25,40,589), (30,48,689), (35,56,789) and (40,64,889), ten in all. Their circumferences add up to 580+4689, so the average is (580+4689)/10.