Space Coconut Crab II

For each T, count the triangles whose three sides are prime numbers summing to T, counting only congruence classes.

Medium5MathNumber theoryNo attempts yetTime limit8sMemory limit512 MB

Problem

The space hunter Ken Marineblue traveled the universe looking for the space coconut crab. The space coconut crab is the largest crustacean known. Its body is more than 400 meters long and its leg span is no shorter than 1000 meters. Many people have reported seeing one, but nobody has captured one yet.

After years of research Ken found out that the crab moves between space and hyperspace by phase drive. Humans cannot travel to hyperspace, so the crab has to be caught in space. The crab keeps still in hyperspace while it charges the energy the phase drive needs, and right after it warps out it moves very slowly. Ken decided to strike at that moment.

The only quantity Ken can measure is the time the crab spent charging energy in hyperspace. CANEL, the artificial intelligence installed on his spaceship Weapon Breaker, analyzed the accumulated data and found that the crab always warps out near the center of a triangle that satisfies all of the following conditions.

  • Each vertex of the triangle is a planet.
  • The length of every side of the triangle is a prime number.
  • The three side lengths add up to TT, the time the crab spent charging energy in hyperspace.

Given the side lengths, CANEL can tell which three planets they are, but more than one triangle may satisfy the conditions. For each TT, count the triangles that satisfy the conditions. Three primes form a triangle only when the two shorter side lengths add up to more than the longest side length.

Input

The input consists of several datasets. Each dataset is a line with a single positive integer TT (1T300001 \le T \le 30000).

The last line holds a single 0 and is not a dataset.

Output

For each dataset, print the number of triangles, one per line. Two triangles count as different only when they are not congruent.