// AOJ 2039: Space Coconut Crab II
// 2017.11.6 bal4u@uu

#include <stdio.h>
#define TM 0
#if TM
#include <time.h>
#endif

#define MAX  30000
char table[MAX+1] = {1,1,0,0};		// zero: if prime

int prime[3250] = {					// prime[39] = 173 = sqrt(MAX), max sz = 3245
  2, 3,  5,  7, 11, 13, 17, 19, 23, 29, 
 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 
 73, 79, 83, 89, 97,101,103,107,109,113, 
127,131,137,139,149,151,157,163,167,173 }; int sz;

void mkprime()
{
	int i, j, k;
	for (i = 0; i < 40; i++) {
		k = prime[i];
		for (j = k<<1; j < MAX; j += k) table[j] = 1;
	}
	for (sz = 39, i = 173; i <= MAX; i += 2) if (!table[i]) prime[sz++] = i;
}

int main()
{
	int t, i, j, k, m, ans;
#if TM
	clock_t start, end;
	start = clock();
#endif
	mkprime();
	while (scanf("%d", &t) && t > 0) {
		if (!(t & 1)) {
			putchar('1' - table[(t>>1)-1]), putchar('\n');
		} else {
			ans = 0, m = t/3;
			for (i = 0; i <= m; i++) for (j = i; j < sz; j++) {
				if ((k = prime[i]+prime[j]) >= t) continue;
				if ((k<<1) > t && !table[t-k] && t-k >= prime[j]) ans++;
			}
			printf("%d\n", ans);
		}
	}
#if TM
	end = clock();
	printf("time %lf\n", (double)(end-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}