﻿ compute prime look-up table
```/*****************************************************************************/
/*									     */
/*  COMPUTE PRIMES							     */
/*  11/04/15 (dkc)							     */
/*									     */
/*****************************************************************************/
#include <math.h>
unsigned int primed(unsigned int *out, unsigned int tsize,
unsigned int *table,unsigned int limit) {
unsigned int d;
unsigned int i,j,k,l,flag,count;
count=tsize;
for (i=0; i<tsize; i++)
out[i]=table[i];
j=table[tsize-1]+1;
/********************/
/*  loop through d  */
/********************/
for (d=j; d<=limit; d++) {
if(d==(d/2)*2) continue;
if(d==(d/3)*3) continue;
if(d==(d/5)*5) continue;
if(d==(d/7)*7) continue;
if(d==(d/11)*11) continue;
/************************************************/
/*  look for prime factors using look-up table	*/
/************************************************/
l=(unsigned int)(10.0+sqrt((double)d));
k=0;
if (l>table[tsize-1])
return(0);
else {
for (i=0; i<tsize; i++) {
if (table[i]<=l)
k=i;
else
break;
}
}
flag=1;
l=k;
for (i=0; i<=l; i++) {
k=table[i];
if ((d/k)*k==d) {
flag=0;
break;
}
}
if (flag==1)
out[count]=d;
count=count+flag;
}
return(count);
}
```