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

Submitted solutions:

code_snippet: #include <stdio.h>
#define MAX 30010

int dy[MAX], prime[MAX];
int n, pcnt;
bool p[MAX];

void getprime(void){
	int i, j;
	for (i=2;i<=15000;i++){
		if (p[i]) continue;
		prime[++pcnt]=i;
		for (j=i*i;j<=15000;j+=i){
			p[j]=1;
		}
	}
}

int main(void){
	int i, j;
	int pi, pj, pk;
	getprime();
	
	for (;;){
		int cnt=0;
		scanf("%d", &n);
		if (n==0) break;
		for (i=1;i<=pcnt;i++){
			pi=prime[i];
			if (pi>=n) break;
			for (j=i;j<=pcnt;j++){
				pj=prime[j];
				if (pi+pj>=n) break;
				pk=n-pi-pj;
				if (pk<pj) break;
				if (p[pk]) continue;
				if (pi<pj+pk && pj<pk+pi && pk<pi+pj){
					cnt++;
				}
			}
		}
		printf("%d\n", cnt);
	}
	return false;
}
accuracy: 1
time_ms: 200
memory_kb: 2976
final_rank: 7

code_snippet: #include <bits/stdc++.h>


using namespace std;
//make -f ../makefile SRC=
/*
for triangle: a + b > c where a, b are the shorter sides

*/


//------------------------------------------------------------------------------
bool DEBUG = false;
const int INF = 1000000000;

const int MAX_V = 30000;
static bool prime[MAX_V+1];

const int K = 3;
const int P = 3245;
static int S[MAX_V+1][K];
static vector<int> primes(P);
//------------------------------------------------------------------------------
void sieve()
{
    prime[0] = false;
    prime[1] = false;

    for (int i=2; i<=MAX_V; i++) prime[i] = true;

    for (int i=2; i*i<=MAX_V; i++)
    {
        if (prime[i])
        {
            for (int j=2*i; j<=MAX_V; j+=i) prime[j] = false;
        }
    }

    int index = 0;
    for (int i=2; i<=MAX_V; i++)
        if (prime[i])
            primes[index++] = i;
}


//------------------------------------------------------------------------------
int solve(int sum)
{
    int res = 0;
    for (int p1=0; p1<P; ++p1)
    {
        if (primes[p1] >= sum) break;
        for (int p2=p1; p2<P; ++p2)
        {
            if (primes[p1]+primes[p2] >= sum) break;
            int c = sum - primes[p1] - primes[p2];
            if (prime[c] && c >= primes[p1] && c >= primes[p2] && c < primes[p1]+primes[p2]) res++;
        }
    }
    return res;
}

//------------------------------------------------------------------------------
int main()
{
    //test(); return 0;
    //DEBUG = true;
    sieve();
    //--------------------------------------------------------------------------
    int N, sum, num;
    while (true)
    {
        num = scanf("%d ", &sum);
        if (sum == 0) break;
        int res = solve(sum);
        printf("%d\n", res);
    }
    //--------------------------------------------------------------------------
    return 0;
}
//------------------------------------------------------------------------------
accuracy: 1
time_ms: 690
memory_kb: 3492
final_rank: 13

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

const int N=30030;
int not_is_prime[N];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<int> P;
    for(int i=2;i<N;i++){
        if(!not_is_prime[i]){
            P.push_back(i);
            for(int j=i+i;j<N;j+=i){
                not_is_prime[j]=1;
            }
        }
    }
    vector<vector<int>> res(4,vector<int>(N));
    res[0][0]=1;
    for(auto p:P){
        for(int i=1;i<4;i++){
            for(int j=p;j<N;j++){
                if(i==3 and p>=j-p)continue;
                res[i][j]+=res[i-1][j-p];
            }
        }
    }
    int n;
    while(cin >> n,n){
        printf("%d\n",res[3][n]);
    }
}
accuracy: 1
time_ms: 70
memory_kb: 3776
final_rank: 8

code_snippet: #include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>


std::vector<int> primes(const int upper_limit) {
	std::vector<bool> is_prime(upper_limit + 1, true);
	for (auto i = 2; i * i <= upper_limit; ++i) {
		if (is_prime[i]) {
			for (auto j = i * i; j <= upper_limit; j += i) {
				is_prime[j] = false;
			}
		}
	}
	std::vector<int> result;
	for (auto i = 2; i <= upper_limit; ++i) {
		if (is_prime[i]) {
			result.push_back(i);
		}
	}
	return result;
}
int main() {
	const auto prime = primes(30000);
	while (true) {
		int n; std::cin >> n;
		if (n == 0) return 0;
		auto count = 0;
		auto greater = std::lower_bound(prime.begin(), prime.end(), n / 3);
		while (greater != prime.end() && *greater * 2 < n) {
			auto mid = std::lower_bound(prime.begin(), prime.end(), (n - *greater) / 2);
			while (*mid <= *greater) {
				if (n - *greater - *mid <= *mid && std::binary_search(prime.begin(), prime.end(), n - *greater - *mid)) {
					++count;
				}
				++mid;
			}
			++greater;
		}
		std::cout << count << std::endl;
	}
}
accuracy: 1
time_ms: 780
memory_kb: 3196
final_rank: 11

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;


vector<int>primes;
void hurui(const int amax) {
	static bool flag = false;
	if (flag)return;
	vector<int>sos;
	sos = vector<int>(amax + 1, true);
	sos[0] = false; sos[1] = false;
	for (int i = 2; i <= amax; ++i) {
		if (sos[i]) {
			for (int j = 2 * i; j <= amax; j += i)sos[j] = false;
		}
	}
	for (int i = 0; i <= amax; ++i) {
		if (sos[i]) {
			primes.push_back(i);
		}
	}
	flag = true;
}

int main() {
	hurui(3e4);
	while (true) {
		int T;cin>>T;
		if(!T)break;
		int ans=0;
		for (int i = 0; i < primes.size(); ++i) {
			for (int j = i; j < primes.size(); ++j) {
				int a=primes[i];
				int b=primes[j];
				int c=T-a-b;
				if(b>c)continue;
				if(a+b<=c)continue;
				if (binary_search(primes.begin(), primes.end(), c)) {
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}


	return 0;
}
accuracy: 1
time_ms: 1630
memory_kb: 3228
final_rank: 15

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


bool is_prime[30001];
vector<int> PRIME;

int main(){

	for(int i = 0; i <= 30000; i++){
		is_prime[i] = true;
	}

	for(int i = 2; i <= sqrt(30000); i++){
		if(is_prime[i]){
			for(int k = 2*i; k <= 30000; k += i){
				is_prime[k] = false;
			}
		}
	}

	for(int i = 2; i <= 30000; i++){
		if(is_prime[i]){
			PRIME.push_back(i);
		}
	}

	int T;
	while(true){
		scanf("%d",&T);
		if(T == 0)break;

		int ans = 0;

		for(int a = 0; a < PRIME.size(); a++){
			if(PRIME[a] > T)break;
			for(int b = a; b < PRIME.size(); b++){
				if(PRIME[a]+PRIME[b] > T)break;
				int c = T -(PRIME[a]+PRIME[b]);

				if(!is_prime[c])continue;

				if(PRIME[b] <= c && (PRIME[a]+PRIME[b]) > c && (PRIME[b]+c) > PRIME[a] && (c+PRIME[a]) > PRIME[b])ans++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
accuracy: 1
time_ms: 490
memory_kb: 3324
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define mk make_pair
int s[30001],ss[30001],c=2;
set<long long>se;
int main(){
  s[0]=2;s[1]=3;ss[2]=ss[3]=1;
  for(int i=2;i<30001;i++){
    int p=0;
    for(int j=2;j*j<=i;j++)
      if(i%j==0)p++;
    if(!p)ss[i]++,s[c++]=i;
  }
  int n;
  while(cin>>n,n){
    se.clear();
    int sum=0;
    for(int i=0;i<c;i++){
      if(s[i]>n/2+1)break;
      for(int j=0;j<c;j++){
        if(s[j]+s[i]>n)break;
        if(n-s[j]-s[i]>0)
          if(ss[n-s[j]-s[i]]){
            int d[3];
            d[0]=s[i];
            d[1]=s[j];
            d[2]=n-s[j]-s[i];
            sort(d,d+3);
            if(!se.count(d[0]*10000000000+d[1]*100000+d[2])&&d[0]+d[1]>d[2]){
              se.insert(d[0]*10000000000+d[1]*100000+d[2]);
              sum++;
            }
          }
        }
      }
      cout<<sum<<endl;
    }
  }
accuracy: 1
time_ms: 6450
memory_kb: 5916
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define mk make_pair
int s[30001],ss[30001],c=2;
unordered_set<long long>se;
int main(){
  s[0]=2;s[1]=3;ss[2]=ss[3]=1;
  for(int i=2;i<30001;i++){
    int p=0;
    for(int j=2;j*j<=i;j++)
      if(i%j==0)p++;
    if(!p)ss[i]++,s[c++]=i;
  }
  int n;
  while(cin>>n,n){
    se.clear();
    int sum=0;
    for(int i=0;i<c;i++){
      if(s[i]>n/2+1)break;
      for(int j=0;j<c;j++){
	if(s[j]+s[i]>n)break;
	if(n-s[j]-s[i]>0)
	  if(ss[n-s[j]-s[i]]){
	    int d[3];
	    d[0]=s[i];
	    d[1]=s[j];
	    d[2]=n-s[j]-s[i];
	    sort(d,d+3);
	    if(!se.count(d[0]*10000000000+d[1]*100000+d[2])&&d[0]+d[1]>d[2]){
		se.insert(d[0]*10000000000+d[1]*100000+d[2]);
	        sum++;
	      }
	  }
      }
    }
    cout<<sum<<endl;
  }
}
accuracy: 1
time_ms: 3390
memory_kb: 5312
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;
const int TMAX = 30000;

pair< vector<int>, vector<int> > eratosthenes(int N){
  vector<int> res;
  vector<int> arr(N);
  for(int i=0; i < N; i++){
    arr[i] = true;
  }
  arr[0] = false;
  arr[1] = false;
  for(int i=2; i*i <= N; i++){
    if(arr[i] == true){
      for(int j=i+i; j < N; j += i){
        arr[j] = false;
      }
    }
  }
  for(int i = 0; i < N; i++){
    if(arr[i] == true) res.push_back(i);
  }
  return pair< vector<int>, vector<int> >(res, arr);
}

bool isTri(int i, int j, int k){
  int a[] = {i, j, k};
  sort(a, a+3);
  if(a[2] < a[1] + a[0]) return true;
  else return false;
}

int main(void){
  int T;
  while(cin >> T, T){
    pair< vector<int>, vector<int> > tmp = eratosthenes(TMAX);
    vector<int> primes = tmp.first;
    vector<int> is_prime = tmp.second;
    int ans = 0;
    for(int i = 0; i < primes.size(); i++){
      for(int j = i; j < primes.size(); j++){
        int k = T - primes[i] - primes[j];
        if(k >= 1 && k >= primes[j] && is_prime[k] == true && isTri(primes[i], primes[j], k)){
          //cout << primes[i] << " " << primes[j] << " " << k << endl;
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
}
accuracy: 1
time_ms: 1180
memory_kb: 3124
final_rank: 14

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_T = 30000;
int T;
ll res[30003];
vector<int> ps;
unordered_map<int,ll> dp[2];

void init(){
  bool f[30003];
  memset( f,0,sizeof(f) );
  for(int i=2;i<=30000;i++){
    if( f[i] ) continue;
    ps.emplace_back(i);
    for(int j=i+i;j<=30000;j+=i)
      f[j] = true;
  }
}

void solve(){
  for(int p : ps){
    dp[0][p]++;
    for( auto q : dp[0] ){
      if( q.first + p > MAX_T ) continue; 
      dp[1][q.first+p] += q.second;
    }
    for( auto q : dp[1] ){
      if( q.first + p > MAX_T ) continue;
      if( q.first <= p )
        continue;      
      res[ q.first + p ] += q.second;
    }
  }
}

int main(){
  init();
  solve();
  while( cin >> T && T ){
    cout << res[T] << endl;
  }
}
accuracy: 1
time_ms: 190
memory_kb: 4108
final_rank: 12

code_snippet: #include<bits/stdc++.h>
#define N 40001
using namespace std;
#define int long long
int T;
bool used[N];
vector<int> prime;


signed main(){
  used[0] = used[1] = 1;
  for(int i=2;i*i<N;i++)
    if(used[i] == 0)
      for(int j=2;j<N/i;j++)used[i*j] = 1;
  for(int i=0;i<N;i++) if(!used[i]) prime.push_back(i);
  
  while(1){
    cin>>T;
    if(T==0)break;
  

  
    int ans = 0;
    for(int i=0;i<prime.size();i++)
    for(int j=i;j<prime.size();j++){
      int a = prime[i];
      int b = prime[j];
      int c = T-(a+b);
      if(b>c)continue;
      if(a+b>=T||used[c] == 1)continue;
      if(a+b>c && a+c>b && b+c>a)ans++;
    }
  cout<<ans<<endl;
  }  
  return 0;
}
accuracy: 1
time_ms: 2150
memory_kb: 3160
final_rank: 16

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	#define MAX 30010
	bool sosu[MAX]={1,1,0};
	for(int i=2;i*i<=MAX;i++)if(!sosu[i])
	for(int j=2*i;j<MAX;j+=i)sosu[j]=true;
	vi so;
	rep(i,MAX)if(sosu[i]==0)so.pb(i);
	int n;
	while(cin>>n,n){
		int out=0;
		int m=lower_bound(all(so),n)-so.begin();
		rep(i,m)loop(j,i,m){
			int t=n-so[i]-so[j];
			if(t<so[j])continue;
			if(sosu[t])continue;
			int ma=max(t,max(so[i],so[j]));
			int sum=t+so[i]+so[j];
			if(sum>2*ma)out++;
		}
		cout<<out<<endl;
	}
}
accuracy: 1
time_ms: 580
memory_kb: 1284
final_rank: 5

code_snippet: #include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 15010
typedef pair<int,int> pii;
typedef pair<pii,int> P;
 
bool check(int a,int b,int c){
    if(a >= b+c || b >= a+c || c >= a+b) return false;
    return true;
}
 
int main(){
    vector<int> prime;
    bool p[MAX];
    fill(p,p+MAX,true);
    p[0] = p[1] = false;
    for(int i = 2 ; i < MAX ; i++){
	if(!p[i]) continue;
	prime.push_back(i);
	for(int j = 2*i ; j < MAX ; j += i){
	    p[j] = false;
	}
    }
    int T;
    while(cin >> T, T){
	int cnt = 0;
	set<P> st;
	int size = prime.size();
	for(int i = 0 ; i < size ; i++){
	    if(prime[i] > T) continue;
	    for(int j = i ; j < size ; j++){
		if(prime[i]+prime[j] > T) continue;
		int k = T-prime[i]-prime[j];
		if(k < 0 || k >= MAX || !p[k]) continue;
		int a[3] = {prime[i],prime[j],k};
		sort(a,a+3);
		if(st.count(P(pii(a[0],a[1]),a[2]))) continue;
		st.insert(P(pii(a[0],a[1]),a[2]));
		if(check(a[0],a[1],a[2])){
		    cnt++;
		}
	    }
	}
	cout << cnt << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 3450
memory_kb: 9288
final_rank: 19

code_snippet: #include<iostream>
#include<vector>
using namespace std;
int P[31000]; vector<int>prime;
int p[31000]; int M = 30000;
int main() {
	p[0] = 1; p[1] = 1;
	for (int i = 2; i*i <= M; i++) {
		for (int j = i*i; j <= M; j += i)p[j] = 1;
	}
	for (int i = 0; i <= M; i++) { if (p[i] == 0)prime.push_back(i); }
	for (int i = 0; i < prime.size(); i++) {
		for (int j = i; j < prime.size(); j++) {
			for (int k = j; k < prime.size(); k++) {
				int v = prime[i] + prime[j] + prime[k];
				if (v > M)continue;
				if (prime[i] + prime[j] <= prime[k])continue;
				P[v]++;
			}
		}
	}
	int n;
	while (true) {
		cin >> n; if (n == 0)break;
		cout << P[n] << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 4140
memory_kb: 3360
final_rank: 17

code_snippet: #include <iostream>
using namespace std;
int n, c, p[5000]; bool prime[30001];
int main() {
	for(int i = 2; i <= 30000; i++) prime[i] = true;
	for(int i = 2; i * i <= 30000; i++) {
		if(!prime[i]) continue;
		for(int j = i * i; j <= 30000; j += i) prime[j] = false;
	}
	for(int i = 2; i <= 30000; i++) {
		if(prime[i]) p[c++] = i;
	}
	while(cin >> n, n) {
		int ret = 0;
		for(int i = 0; i < c && p[i] < n; i++) {
			for(int j = i; j < c && p[i] + p[j] < n; j++) {
				int w = n - p[i] - p[j];
				if(prime[w] && p[i] + p[j] > w && w >= p[j]) ret++;
			}
		}
		cout << ret << endl;
	}
}
accuracy: 1
time_ms: 650
memory_kb: 3148
final_rank: 10

code_snippet: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
// #include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n)*(n)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;


int primes[3000];
int siz = 0;
int num[40000]={0};
bool isprime[200000]={false};

int main() {
  for(int i=2;i<20000;i++){
    if(isprime[i])continue;
    primes[siz++]=i;
    for(int j=i*2;j<20000;j+=i){
      isprime[j]=true;
    }
  }
  for(int a=0;primes[a]<=15000;a++){
    for(int b=a;primes[b]<=15000;b++){
      for(int c=b;primes[c]<=15000;c++){
        if(primes[a]+primes[b]<=primes[c])continue;
        if(primes[a]+primes[b]+primes[c]>30000)continue;
        num[primes[a]+primes[b]+primes[c]]++;
        // LOG("%d %d %d\n",primes[a],primes[b],primes[c]);
      }
    }
  }
  // cout << "end works" << endl;

  int T;
  while(cin>>T,T){
    cout << num[T] << endl;
  }
}
accuracy: 1
time_ms: 660
memory_kb: 1320
final_rank: 6

code_snippet: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_T = 30000;
const int MAX_SIDE = (MAX_T - 1) / 2;

/* typedef */

typedef vector<int> vi;

/* global variables */

bool primes[MAX_SIDE + 1];
vi pnums;
int np;

/* subroutines */

void calc_prime(int max_p) {
  primes[0] = primes[1] = false;
  for (int p = 2; p <= max_p; p++) primes[p] = true;

  for (int p = 2; p * p <= max_p; p++)
    if (primes[p])
      for (int q = p * p; q <= max_p; q += p) primes[q] = false;

  for (int p = 2; p <= max_p; p++)
    if (primes[p]) pnums.push_back(p);

  np = pnums.size();
}

/* main */

int main() {
  calc_prime(MAX_SIDE);

  for (;;) {
    int t;
    cin >> t;
    if (t == 0) break;

    int count = 0;
    int mina = t / 3;
    int maxside = (t - 1) / 2;
  
    for (vi::iterator ait = pnums.begin(); ait != pnums.end(); ait++) {
      int& a = *ait;
      if (a < mina) continue;
      if (a > maxside) break;

      int minb = (t - a) / 2;
      
      for (vi::iterator bit = pnums.begin(); bit != pnums.end(); bit++) {
	int& b = *bit;
	if (b < minb) continue;
	if (b > a) break;

	int c = t - (a + b);
	if (c > 0 && c <= b && primes[c]) {
	  count++;
	}
      }
    }

    cout << count << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 90
memory_kb: 1244
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;
vector<int>P;
int pr[30001];
void era(){
	pr[0]=pr[1]=1;
	for(int i=2;i*i<=30000;i++){
		if(pr[i]==0){
			for(int j=i+i;j<=30000;j+=i){
				pr[j]=1;
			}
		}
	}
	for(int i=2;i<=30000;i++){
		if(pr[i]==0)P.push_back(i);
	}
}
int main(){
	era();
	for(int t;cin>>t,t;){
		int ans=0;
		for(int i=0;i<P.size();i++){
			if(t<P[i]*3)break;
			for(int j=i;j<P.size();j++){
				int k=t-P[i]-P[j];
				if(k<P[j])break;
				if(k<P[i]+P[j] && pr[k]==0){
					//cout<<P[i]<<" "<<P[j]<<" "<<k<<endl;
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
	
	return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 1364
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;

inline bool isPrime(int a){
  if(a<=1)return false;
  for(int i=2;i*i<=a;i++){
    if(a%i==0)return false;
  }
  return true;
}

int main(){
  bool pt[30030] = {};
  vector<int> pl;
  for(int i=0;i<=30000;i++){
    if(isPrime(i)){
      pt[i] = 1; pl.push_back(i);
    }
  }

  int t;
  while(scanf("%d",&t),t){
    int res = 0;
    for(int i=0;i<(int)pl.size();i++){
      for(int j=i;j<(int)pl.size();j++){
	int rem = t - pl[i] - pl[j];
	if(rem < pl[j])break;
	if(pl[i]+pl[j]>rem && pt[rem])res++;
      }
    }
    printf("%d\n",res);
  }
}
accuracy: 1
time_ms: 140
memory_kb: 1272
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;

inline bool isPrime(int a){
  if(a<=1)return false;
  for(int i=2;i*i<=a;i++){
    if(a%i==0)return false;
  }
  return true;
}

int main(){
  bool pt[30030] = {};
  vector<int> pl;
  for(int i=0;i<=30000;i++){
    if(isPrime(i)){
      pt[i] = 1; pl.push_back(i);
    }
  }

  int t;
  while(cin >> t,t){
    int res = 0;
    for(int i=0;i<(int)pl.size();i++){
      for(int j=i;j<(int)pl.size();j++){
	int rem = t - pl[i] - pl[j];
	if(rem < pl[j])break;
	if(pl[i]+pl[j]>rem && pt[rem])res++;
      }
    }
    cout << res << endl;
  }
}
accuracy: 1
time_ms: 140
memory_kb: 1280
final_rank: 3