#include<stdio.h>
#include<bitset>
#include<vector>
int main()
{
	const int N=30001;
	std::bitset<N>p;
	std::vector<int>v;
	int i,j,x[3][N]={0};
	for(i=2;i<N;++i)if(!p[i])for(v.push_back(i),j=i*i;j<N;j+=i)p[j]=1;
	for(i=0;i<v.size();++i)for(x[0][v[i]]=1,j=2;j<N-v[i];++j)
	{
		x[1][j+v[i]]+=x[0][j];
		if(v[i]<j)x[2][j+v[i]]+=x[1][j];
	}
	while(scanf("%d",&i),i)printf("%d\n",x[2][i]);
	return 0;
}