本文发表在 rolia.net 枫下论坛#include <stdio.h>
#include <math.h>
#include <stdlib.h>
unsigned long odd[10000];
unsigned long odd_num=0;
unsigned long max=4000;
unsigned long checkOdd (unsigned long n)
{
unsigned long m = (unsigned long)sqrt(n);
//printf("n=%d m=%d\n",n,m);
if ( n==3)
return 0;
for ( unsigned long i=1; i< odd_num;i++) {
if ( odd[i]> m)
return 0;
if ( n%odd[i] ==0 )
return odd[i];
}
for ( unsigned long i=odd[odd_num-1]+2; i<= m ;i+=2) //here odd_num>=2
{
if (n%i ==0)
return i;
}
return 0;
}
main()
{
odd[odd_num++]=2;
printf("pow :%d\n",pow(2,3) );
printf("odd :2\n");
for ( unsigned long i=3;i< max;i+=2) {
if ( checkOdd(i) == 0) {
odd[odd_num++]=i;
printf("odd :%d\n",i);
}
}
printf ( "find odd %d\n",odd_num);
unsigned long multi= 2;
for ( unsigned long i=1;i< odd_num; i++ ) {
multi *=odd[i];
unsigned long Pn = multi+1;
unsigned long find=checkOdd(Pn);
if ( find >0 )
{
printf("haha : Pn=%d Pn-1 =%d find %d\n",Pn,odd[i],find);
}
if ( Pn > 0x8000000)
break;
}
}更多精彩文章及讨论,请光临枫下论坛 rolia.net
#include <math.h>
#include <stdlib.h>
unsigned long odd[10000];
unsigned long odd_num=0;
unsigned long max=4000;
unsigned long checkOdd (unsigned long n)
{
unsigned long m = (unsigned long)sqrt(n);
//printf("n=%d m=%d\n",n,m);
if ( n==3)
return 0;
for ( unsigned long i=1; i< odd_num;i++) {
if ( odd[i]> m)
return 0;
if ( n%odd[i] ==0 )
return odd[i];
}
for ( unsigned long i=odd[odd_num-1]+2; i<= m ;i+=2) //here odd_num>=2
{
if (n%i ==0)
return i;
}
return 0;
}
main()
{
odd[odd_num++]=2;
printf("pow :%d\n",pow(2,3) );
printf("odd :2\n");
for ( unsigned long i=3;i< max;i+=2) {
if ( checkOdd(i) == 0) {
odd[odd_num++]=i;
printf("odd :%d\n",i);
}
}
printf ( "find odd %d\n",odd_num);
unsigned long multi= 2;
for ( unsigned long i=1;i< odd_num; i++ ) {
multi *=odd[i];
unsigned long Pn = multi+1;
unsigned long find=checkOdd(Pn);
if ( find >0 )
{
printf("haha : Pn=%d Pn-1 =%d find %d\n",Pn,odd[i],find);
}
if ( Pn > 0x8000000)
break;
}
}更多精彩文章及讨论,请光临枫下论坛 rolia.net