The Gougu Theorem

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

  Pythagorean Theorem is "humanity's greatest scientific discoveries of the ten" is a basic elementary geometry theorems. "This theorem has a very long history, almost all ancient civilizations (Greece, China, Egypt, Babylon, India, etc.) have studied this theorem. Pythagorean Theorem in the West known as the Pythagorean Theorem, are said to Ancient Greek mathematician and philosopher Pythagoras (Pythagoras, BC572 ~ BC497) was first discovered in BC550.

Pythagorean Theorem in China known as the Gougu/勾股 Theorem. Around 1100 BC, the Western Zhou period, the ancient Chinese mathematician, Shanggao, first described the Gougu Theorem. In the famous ancient mathematics book, 《九章算术》,the proof was given (left). The Gougu Theorem is that "in the right triangle, the sum of the squares of two right sides is equal to the square of the hypotenuse." In other words, the three sides (a, b, c) of right-angled triangle satisfies the following equation:
a2+b2=c2
  Where a is called 勾/Gou, b is 股/Gu, and c is 弦/Xian.
  For given c, how many different positive integer solutions are there? ((a,b,c)are relatively-prime. ) It is an interesting problem.
  Now, your task is to solve it.

Input

    There are several test cases; each test case contains one positive integer c (0 < c < 230 ) in a line. c = 0 is the end of input and need not to process. 

Output

  For each test case, your program should output by following format:
Case #:
There are n solution(s).
a^2 + b^2 = c^2
…..(total n line(s) )….

Where # is the test case number starting from 1, two consecutive cases should be separated by a single blank line.
For each given c, output all solutions satisfying:
a2+b2=c2
Each solution should be in one line, and in order a

Sample Input

65
20
0

Sample Output

Case 1:
There are 2 solution(s).
16^2 + 63^2 = 65^2
33^2 + 56^2 = 65^2

Case 2:
There are 0 solution(s).

Hint

 

Source

2010湖南大学校赛