Pythagorean Triangles

Many lattice triangles are formed in an (N × N) grid, but not all of them are Pythagorean (Right angled) triangles. Given the value of N your job is to write a program that produces the number of lattice triangles in an (N × N ) grid. A lattice triangle is triangle whose three vertices are lattice points. A lattice point in two dimensional Cartesian coordinate system is a point whose abscissa and ordinate are integers. Input The input file contains at most 15 lines of inputs. Each line contains an integer N (0 < N < 2001). Input is terminated by a line containing a single zero. This line should not be processed. Output For each value of N produce one line of output which contains an integer T. Here T denotes the total number of right angled triangles in that (N × N ) grid. Sample Input 10 20 30 0 Sample Output 23596 418716 2288304