用素数筛法筛一次,然后验算下就OK
#include <stdio.h>
#include <string.h>
int t[33000], prime[3000], p= 0;
int m, count;
void init()
{
memset (t, 0, sizeof(t));
for ( int i = 2 ; i < 33000 ; i++ )
{
if( !t[i] )
{
prime[p++]= i;
for ( int j = i*2; j < 33000 ; j += i )
t[j]= 1;
}
}
}
int main()
{
init();
while ( scanf("%d", &m), m )
{
count=0;
int mid= m>>1;
int i, j, a;
for ( i = 0; prime[i] <= mid; i++ )
{
a= prime[i];
if ( !t[m-a] )
count++;
}
printf("%d\n", count);
}
return 0;
}