Problem:
Problem A: Space Coconut Crab II

A space hunter, Ken Marineblue traveled the universe, looking for the space coconut crab. The
space coconut crab was a crustacean known to be the largest in the universe. It was said that
the space coconut crab had a body of more than 400 meters long and a leg span of no shorter
than 1000 meters long. Although there were numerous reports by people who saw the space
coconut crab, nobody have yet succeeded in capturing it.

After years of his intensive research, Ken discovered an interesting habit of the space coconut
crab. Surprisingly, the space coconut crab went back and forth between the space and the
hyperspace by phase drive, which was the latest warp technology. As we, human beings, was
not able to move to the hyperspace, he had to work out an elaborate plan to capture them.
Fortunately, he found that the coconut crab took a long time to move between the hyperspace
and the space because it had to keep still in order to charge a sufficient amount of energy for
phase drive. He thought that he could capture them immediately after the warp-out, as they
moved so slowly in the space.

He decided to predict from the amount of the charged energy the coordinates in the space
where the space coconut crab would appear, as he could only observe the amount of the charged
energy by measuring the time spent for charging in the hyperspace. His recent spaceship,
Weapon Breaker, was installed with an artificial intelligence system, CANEL. She analyzed the
accumulated data and found another surprising fact; the space coconut crab always warped out
near to the center of a triangle that satisfied the following conditions:

each vertex of the triangle was one of the planets in the universe;

the length of every side of the triangle was a prime number; and

the total length of the three sides of the triangle was equal to T, the time duration the
space coconut crab had spent in charging energy in the hyperspace before moving to the
space.

CANEL also devised the method to determine the three planets comprising the triangle from
the amount of energy that the space coconut crab charged and the lengths of the triangle sides.
However, the number of the candidate triangles might be more than one.

Ken decided to begin with calculating how many different triangles were possible, analyzing
the data he had obtained in the past research. Your job is to calculate the number of different
triangles which satisfies the conditions mentioned above, for each given T.

Input

The input consists of multiple datasets. Each dataset comes with a line that contains a single
positive integer T (1 ≤ T ≤ 30000).

The end of input is indicated by a line that contains a zero. This should not be processed.

Output

For each dataset, print the number of different possible triangles in a line. Two triangles are
different if and only if they are not congruent.

Sample Input

10
12
15
777
4999
5000
0

Output for the Sample Input

0
1
2
110
2780
0

Solution in C++ (judge verdict: Accepted)

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

bool is_prime[30001];

int main(){
  int side_sum;

  memset(is_prime,true,sizeof(is_prime));
  is_prime[0] = false;
  is_prime[1] = false;
  vector<int> prime;
  for(int i=0;i<=30000;i++){
    if(!is_prime[i]) continue;
    prime.push_back(i);
    for(int j=i+i;j<=30000;j+=i){
      is_prime[j] = false;
    }
  }

  while(~scanf("%d",&side_sum)){
    if(side_sum == 0) break;
    int res = 0;
    map<vector<int>,bool> visited;

    for(int prime_i = 0; prime_i < prime.size(); prime_i++){

      int center_side = prime[prime_i];
      if(2 * center_side >= side_sum) break;

      int remainings = side_sum - center_side;
      if(remainings <= 0) break;
      
      for(int prime_j = 0; prime_j < prime.size(); prime_j++){
        int left_side = prime[prime_j];
        if(left_side >= remainings) break;

        int right_side = remainings - left_side;
        if(right_side <= 0) break;
        if(!is_prime[right_side]) continue;
        if(left_side > right_side) break;

        vector<int> used;
        used.push_back(center_side);
        used.push_back(left_side);
        used.push_back(right_side);
        sort(used.begin(),used.end());
        if(used[0] + used[1] <= used[2]) continue;

        if(visited.find(used) != visited.end()) continue;

        visited[used] = true;
        res++;
      }
    }
    printf("%d\n",res);
  }
}