/* PRIMES.C - Sieve of Eratosthenes benchmark from BYTE Aug.83, p.112 */

#include "stdio.h"
#define TRUE 1
#define FALSE 0
#define SIZE 8190	/* size of number array */
#define NTIMES 10	/* number of iterations */

char flag[SIZE+1];

main()
{
	int i,j,k, count, prime;

	printf("%d iterations: ", NTIMES);

	for (i=1; i <= NTIMES; i++) {
		count=0;
		for (j=0; j <= SIZE; j++)
			flag[j]=TRUE;
		for (j=0; j <= SIZE; j++) {
			if (flag[j] == TRUE) {
				prime = j + j + 3;
				for (k=j+prime; k <= SIZE; k += prime)
					flag[k]=FALSE;	/* discard multiples */
				count++;
			}
		}
	}
	printf("%d primes.\n", count);
	exit(0);
}
