rif_xu@eds.ericsson.se (07/19/89)
Hi, does anybody out there in Netland have a program (preferably written i C or Pascal) which finds primenumbers from 1 to a-very-big-number (I have the Sieve of E. but I can't generate those big primes I want on a MacII-maximum up to 50000). Thanks Sigge
jb@cadlab.UUCP (Joerg Battermann) (07/27/89)
In article <1658@eds.ericsson.se> rif_xu@eds.ericsson.se writes: > > Hi, > does anybody out there in Netland have a program > (preferably written i C or Pascal) which finds > primenumbers from 1 to a-very-big-number (I have the > Sieve of E. but I can't generate those big primes I > want on a MacII-maximum up to 50000). > > > Thanks Sigge #include<stdio.h> #include<math.h> main() { #define max 1000000 /* primenumbers <= 1.000.000 */ register long i,j,k,l; long a[max],x,lmax; float fmax= max; printf("Primenumbers from x to y\n"); printf("x:"); scanf("%ld",&x); printf("\ny:"); scanf("%ld",&lmax); fmax = lmax; k =ceil( sqrt(fmax)); for(i=2;i<lmax;i++) a[i]=i; i=2; while( i< k ) { if(a[i] != 0) for(j = 2; (l=i*j)< lmax; j++) a[l] = 0; i++; } for(i=x;i<lmax;i++) if(a[i]!=0) printf("%ld\n",i); }