[racket] How to verify prime numbers.

From: 飞刀 (fly3ds at qq.com)
Date: Thu Jul 14 01:56:36 EDT 2011

Hello everyone,

I want a program to verify prime numbers which can be runned in mzscheme.  The following is C source.  I don't konwn how to convert it to lisp.

Thanks.

#include <stdio.h>
#include <time.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#define E6 1000000

char table[E6];
int num = 0;
//int prime[E8];

void cal_table()
{
int j, k;
time_t t1, t2;
t1 = time(NULL);
memset(table, 1, E6);
for (j = 2 ; j < E6; j++) {
if ( table[j] ) {
num++;
for ( k = j + j; k < E6; k += j )
{
table[k] = 0;
}
}
}
t2 = time(NULL);
printf("Totaly %d primes until E6, cost %d time_t.\n", num, t2 - t1);
}

/*
void init_prime()
{
int i;
num = 0;
printf("Init prime start...");
for (i = 2; i < 2*E9; i++) {
if (table[i])
prime[num++] = i;
}
printf("Init prime finished...");
}
*/

int main()
{
int i;
cal_table();
//init_prime();
return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110714/94586c49/attachment.html>

Posted on the users mailing list.