Вот программа на C.
Код:
#include <stdio.h>
#include <malloc.h>
#include <time.h>
#define TEST(f,x)   (*(f+(x)/16)&(1<<(((x)%16L)/2)))
#define SET(f,x)   *(f+(x)/16)|=1<<(((x)%16L)/2)
int
main(int argc, char *argv[])
{
  unsigned char *feld=NULL, *zzz;
  unsigned long teste=1, max, mom, hits=1, count, alloc, s=0, e=1;
  time_t begin;
  if (argc > 1)
    max = atol (argv[1]) + 10000;
  else
    max = 14010000L;
  while (feld==NULL)
        zzz = feld = malloc (alloc=(((max-=10000L)>>4)+1L));
  for (count=0; count<alloc; count++) *zzz++ = 0x00;
  printf ("Searching prime numbers to : %ld\n", max);
  begin = time (NULL);
  while ((teste+=2) < max)
        if (!TEST(feld, teste)) {
                if  (++hits%2000L==0) {printf (" %ld. prime number\x0d", hits); fflush(stdout);}
                for (mom=3L*teste; mom<max; mom+=teste<<1) SET (feld, mom);
                }
  printf (" %ld prime numbers foundn %ld secs.\n\nShow prime numbers", 
          hits, time(NULL)-begin);
  while (s<e) {
        printf ("\n\nStart of Area : "); fflush (stdout); scanf ("%ld", &s);
        printf ("End   of Area : ");     fflush (stdout); scanf ("%ld", &e);
        count=s-2; if (s%2==0) count++;
        while ((count+=2)<e) if (!TEST(feld,count)) printf ("%ld\t", count);
        }
  free (feld);
  return 0;
}
Вот прогон до миллиарда.
Код:
Microsoft Windows XP [Версия 5.1.2600]
(С) Корпорация Майкрософт, 1985-2001.
C:\Documents and Settings\Someone>d:\Programming\CBuilder5\Projects\sieve_c\siev
e_c.exe 1000000000
Searching prime numbers to : 1000000000
 50847534 prime numbers foundn 26 secs.
Show prime numbers
Start of Area : 999999000
End   of Area : 1000000000
999999001       999999017       999999029       999999043       999999059
999999067       999999103       999999107       999999113       999999131
999999137       999999151       999999163       999999181       999999191
999999193       999999197       999999223       999999229       999999323
999999337       999999353       999999391       999999433       999999487
999999491       999999503       999999527       999999541       999999587
999999599       999999607       999999613       999999667       999999677
999999733       999999739       999999751       999999757       999999761
999999797       999999883       999999893       999999929       999999937
Start of Area : End   of Area : ^C
C:\Documents and Settings\Someone>
Вот прогон до 14000000.
Код:
C:\Documents and Settings\Someone>d:\Programming\CBuilder5\Projects\sieve_c\siev
e_c.exe
Searching prime numbers to : 14000000
 910077 prime numbers foundn 1 secs.
Show prime numbers
Start of Area : 13999000
End   of Area : 14000000
13999003        13999009        13999057        13999079        13999099
13999121        13999133        13999147        13999159        13999169
13999171        13999189        13999213        13999253        13999267
13999273        13999289        13999291        13999301        13999309
13999351        13999369        13999393        13999397        13999399
13999421        13999423        13999441        13999459        13999463
13999471        13999477        13999481        13999519        13999529
13999537        13999549        13999597        13999603        13999621
13999651        13999673        13999691        13999703        13999723
13999729        13999747        13999757        13999759        13999781
13999787        13999813        13999831        13999871        13999873
13999877        13999889        13999919        13999957        13999961
13999969        13999981