找一個質數,做為通信檢查用。
#include <stdio.h>
#include <math.h>
unsigned int test_number;
unsigned int not_prime(unsigned int x)
{
unsigned int q_t;
unsigned int i;
if ( !(x & 0x1) ) return 2;
q_t = sqrt(x);
for (i=3; i<=q_t; i+=2)
if ( x % i == 0 ) return i;
return 0;
}
void main()
{
test_number = 0x80000000;
if( test_number % 2 == 0 ) test_number--;
while( not_prime(test_number) )
test_number -= 2;
printf("%d\n", test_number);
}
沒有留言:
張貼留言