0001 #include <stdio.h> 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 srand ( ( unsigned int ) time ( NULL ) ); //设置随机种子 0013 if ( 2 > argc ) { printf ( "Usage: %s <maxInt>\n", argv[0] ); return -1; } 0014 int n = atoi ( argv[1] ); //简化起见,不考虑非正的情况 0015 Eratosthenes ( n, PRIMEFILE ); 0016 for ( int i = 0; i < 13; i++ ) { //做13次随机测试(限于MAX_RAND,覆盖范围不超过0x7FFF) 0017 int low = dice ( n ); 0018 printf ( "The smallest prime number no less than %8d (%05X) is %8d\n", low, low, primeNLT ( low, n, PRIMEFILE ) ); 0019 } 0020 for ( int i = 0; i < 13; i++ ) { //做13次等间距测试 0021 printf ( "The smallest prime number no less than %8d (%05X) is %8d\n", n * i / 13, n * i / 13, primeNLT ( n * i / 13, n, PRIMEFILE ) ); 0022 } 0023 return 0; 0024 }