改用快速開根
#include <stdio.h>
unsigned int test_number;
float SquareRootFloat(float number)
{
long i;
float x, y;
const float f = 1.5F;
x = number * 0.5F;
y = number;
i = * ( long * ) &y;
i = 0x5f3759df - ( i >> 1 );
y = * ( float * ) &i;
y = y * ( f - ( x * y * y ) );
y = y * ( f - ( x * y * y ) );
return number * y;
}
unsigned int not_prime(unsigned int x)
{
unsigned int q_x;
unsigned int i;
if ( !(x & 0x1) ) return 2;
q_x = SquareRootFloat(x);
for (i=3; i<=q_x; i+=2)
if ( x % i == 0 ) return i;
return 0;
}
void main()
{
test_number = 0x73d58987;
if ( test_number % 2 == 0 ) test_number--;
while ( not_prime(test_number) )
test_number -= 2;
printf("%d\n", test_number);
}
沒有留言:
張貼留言