0001 #include <cstdio> 0002 #include "_share/rand.h" 0003 #include "Bitmap/Bitmap.h" 0004 #include "Eratosthenes.h" 0005 #include "primeNLT.h" 0006 0007 /****************************************************************************************** 0008 * 主函数 0009 ******************************************************************************************/ 0010 #define PRIMEFILE "prime-bitmap.txt" //用于记录指定区间内素数分布的比特图文件 0011 int main ( int argc, char* argv[] ) { 0012 if ( 2 > argc ) { printf ( "Usage: %s <maxInt>\n", argv[0] ); return -1; } 0013 srand((unsigned int)time(NULL)); //随机种子 0014 //srand( 31415926 ); //固定种子(假种子,调试用) 0015 int n = atoi( argv[1] ); //简化起见,不考虑非正的情况 0016 Eratosthenes( n, PRIMEFILE ); 0017 for ( int i = 0; i <= 13; i++ ) { //做13次随机测试(限于MAX_RAND,覆盖范围不超过0x7FFF) 0018 int low = dice( n ); 0019 printf( "The smallest prime number no less than %8d (%05X) is %8d\n", low, low, 0020 primeNLT( low, n, PRIMEFILE ) ); 0021 } 0022 for ( int i = 0; i < 13; i++ ) { //做13次等间距测试 0023 printf( "The smallest prime number no less than %8d (%05X) is %8d\n", n * i / 11, 0024 n * i / 11, primeNLT( n * i / 11, n, PRIMEFILE ) ); 0025 } 0026 return 0; 0027 }