#include
#include
#include
#define UBOUND 0x18000000
/* #define UBOUND UINT_MAX */
#define INDEX_BOUND (UBOUND/2)
#define PRIME_FILE "prime.bin"
int main(void)
{
FILE *fp;
unsigned i, j;
unsigned char *workarea;
unsigned p=2;
fp = fopen(PRIME_FILE, "wb");
if (!fp) {perror(PRIME_FILE); return 1;}
fwrite(&p, sizeof(unsigned), 1, fp);
workarea = malloc(INDEX_BOUND);
memset(workarea, 0, INDEX_BOUND);
for (p=3, i=0; p<=UBOUND/2; ++i, p=2*i+3)
{
#define CHECK_BITS 0xffff
if (!((~p)&CHECK_BITS)) printf("%x\n", p);
if (!workarea[i])
{
fwrite(&p, sizeof(unsigned), 1, fp);
for (j=i+p; j
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/