Browse Groups

• /********************/ * to e-mail to somebody?, * worth to try, * i found this by my self, * so its my merit(proud) anyway even if someone already discovered
Message 1 of 1 , Mar 23, 2004
View Source
/********************/
* to e-mail to somebody?,
* worth to try,
* i found this by my self,
* so its my merit(proud) anyway even if someone already discovered this algoritm
*
* date: long time ago
********************/

Hello,
i've been researching by my self the logic of prime numbers... also i've made some algoritms from scratch
i didn't know nothing about prime numbers until i study them by my self...

since i don't know much kind of algoritms to "fill a table of prime numbers exists"... i know the basic
algoritm:

char *fillprimetable1(unsigned long si) {
char *isprimet;
unsigned long i,j;
isprimet=malloc(si);
if(isprimet==NULL) {
fprintf(stderr,"Maybe not enought mem to perform operation\n");
return NULL;
};
memset(isprimet,2,si);
for(i=1;i<si;i++) {
for(j=2;j<i;j++) {
if((i%j)==0) {
isprimet[i]=0;
break;
};
};
if(isprimet[i]==2){isprimet[i]=1;}
};

return isprimet;
};

wich is kind of slow..., so with my own studies about primes, i've been able to develop another algoritm
it's much more faster (like, filling a *'boolean table '[as this basic algoritm]' with 1 million numbers less than a second, 10 million
in about 3 seconds, 100 million in about 46 seconds) on a Pentium3 900Mhz (downclocked to 700Mhz (damn 66mhz old ram)), well whatever
i guess i made my point.. what i want to know is.. if i discovered something new, or i reinvented the whell?
anyway i'd like to seek for prime information and researches, where can i get stuff like that..

*'boolean table', it looks like if(isprime[number]) filled with falses and trues

and i researched that algoritm is possible to be improved!

/*screenshots*/
Filling a prime table of size: 10000 algoritm 0 (my algoritm)
checked 10000 numbers in 0 Seconds
Writing to file: alg1.txt
Writed 1231 primes
Filling a prime table of size: 10000 algoritm 1 (basic algoritm)
checked 10000 numbers in 1 Seconds
Writing to file: alg2.txt
Writed 1231 primes
Press any key to continue
/************/ end of screen shot
Filling a prime table of size: 100000 algoritm 0 (my algoritm)
checked 100000 numbers in 0 Seconds
Writing to file: alg1.txt
Writed 9594 primes
Filling a prime table of size: 100000 algoritm 1 (basic algoritm)
checked 100000 numbers in 47 Seconds
Writing to file: alg2.txt
Writed 9594 primes
Press any key to continue
/************/ end of screen shot
Filling a prime table of size: 1000000 algoritm 0 (my algoritm)
checked 1000000 numbers in 0 Seconds
Writing to file: alg1.txt
Writed 78500 primes
Filling a prime table of size: 1000000 algoritm 1 (basic algoritm)
/************/ (i couldn't wait to long for the basic algoritm results)
Filling a prime table of size: 10000000 algoritm 0 (my algoritm)
checked 10000000 numbers in 4 Seconds
Writing to file: alg1.txt
Writed 664581 primes
Filling a prime table of size: 10000000 algoritm 1 (basic algoritm)
/************/ (i couldn't wait to long for the basic algoritm results)
Filling a prime table of size: 100000000 algoritm 0 (my algoritm)
checked 100000000 numbers in 46 Seconds
Writing to file: alg1.txt
Writed 5761457 primes
Filling a prime table of size: 100000000 algoritm 1 (basic algoritm)
/************/ (i couldn't wait to long for the basic algoritm results)

functions call: (not the algoritm)

printf("Filling a prime table of size: %d algoritm 0 (my algoritm)\n",MANY);
hi=time(NULL);
isprime=fillprimetable(MANY);
printf("checked %d numbers in %d Seconds\n",MANY,time(NULL)-hi);
printf("Writing to file: alg1.txt\n");
out=fopen("alg1.txt","wb+");
for(i=0,j=0;i<MANY;i++) {
if(isprime[i]) {
j++;
fprintf(out,"%d\n",i);
};
};
fclose(out);
printf("Writed %d primes\n",j);
free(isprime) ;

printf("Filling a prime table of size: %d algoritm 1 (basic algoritm)\n",MANY);
hi=time(NULL);
isprime=fillprimetable1(MANY);
printf("checked %d numbers in %d Seconds\n",MANY,time(NULL)-hi);
printf("Writing to file: alg2.txt\n");
out=fopen("alg2.txt","wb+");
for(i=0,j=0;i<MANY;i++) {
if(isprime[i]) {
j++;
fprintf(out,"%d\n",i);
};
};
fclose(out);
printf("Writed %d primes\n",j);
////////////////////////////////////////////////////////////////////////////

date:
23-3-2004

I believe that algoritm could work as an offset (for low mem) like from 5000 to 6000 (instead 0-6000)

well i might have more own research information about primes that might be usefull for algoritms or understanding more about primes...

i start my research from scratch, maybe a fall in anothers errors or maybe i could inovate...

[Non-text portions of this message have been removed]
Your message has been successfully submitted and would be delivered to recipients shortly.
• Changes have not been saved
Press OK to abandon changes or Cancel to continue editing
• Your browser is not supported
Kindly note that Groups does not support 7.0 or earlier versions of Internet Explorer. We recommend upgrading to the latest Internet Explorer, Google Chrome, or Firefox. If you are using IE 9 or later, make sure you turn off Compatibility View.