- 注册时间
- 2007-12-26
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 92615
- 在线时间
- 小时
|
发表于 2009-3-3 21:24:00
|
显示全部楼层
优化 102# 无心人 的程序
- #include <stdio.h>
-
- #include "../../../HugeCalc_API/CppAPI/Include/HugeCalc.h" // 公共接口
- #include "../../../HugeCalc_API/CppAPI/Include/HugeInt.h" // 10进制系统
-
- #pragma message( "automatic link to ../../../HugeCalc_API/CppAPI/Lib/HugeCalc.lib" )
- #pragma comment( lib, "../../../HugeCalc_API/CppAPI/Lib/HugeCalc.lib" )
-
- #define DIGIT_MAX 128
-
- BOOL filter( const CHugeInt& hugeNum )
- {
- LPCTSTR p = (LPCTSTR)hugeNum;
- BOOL b2 = FALSE;
-
- do
- {
- if ( 0 == (((UINT32)*p) & 1) )
- {
- if ( '0' == *p )
- {
- return FALSE;
- }
-
- b2 = TRUE;
- break;
- }
- else if ( '5' == *p )
- {
- break;
- }
- } while( NULL != *(++p) );
-
- if ( NULL != *p )
- {
- if ( b2 )
- {
- while ( NULL != *(++p) )
- {
- if ( '0' == *p || '5' == *p )
- {
- return FALSE;
- }
- }
- }
- else
- {
- while ( NULL != *(++p) )
- {
- if ( 0 == (((UINT32)*p) & 1) )
- {
- return FALSE;
- }
- }
- }
- }
-
- return TRUE;
- }
-
- int main(int argc, char* argv[])
- {
- UINT32 exp7, exp3, exp2, count = 0;
- CHugeInt huge7, huge73, huge732;
-
- printf( "Call %s\n", HugeCalc::GetVer());
- if ( HC_LICENSE_NONE == HugeCalc::GetLicenseLevel())
- {
- printf( "\n警告:您未通过 HugeCalc.dll 的许可认证!\n" \
- "\n解决方案可选下列方案之一:" \
- "\n 一、请将本程序移动到“/CopyrightByGuoXianqiang/[../]”目录下运行;" \
- "\n 二、或请在 HugeCalc.chm 中进行注册(一劳永逸)。\n\n" );
-
- system( "pause" );
- return (-1);
- }
-
- HugeCalc::EnableTimer( TRUE );
- HugeCalc::ResetTimer();
-
- exp7 = 0;
- huge7 = 1;
- do
- {
- exp3 = 0;
- huge73 = huge7;
- do
- {
- exp2 = 0;
- huge732 = huge73;
- do
- {
-
- if ( filter( huge732 ) )
- {
- fprintf(stdout, "%s No.%u\texp( 2, 3, 7 ) = ( %u, %u, %u )\n",
- HugeCalc::GetTimerStr( FT_HHMMSS_ms ), ++count, exp2, exp3, exp7 );
- fflush(stdout);
- }
-
- } while( ++exp2, ( huge732 *= 2 ).GetDigits() <= DIGIT_MAX );
-
- } while( ++exp3, ( huge73 *= 3 ).GetDigits() <= DIGIT_MAX );
-
- } while( ++exp7, ( huge7 *= 7 ).GetDigits() <= DIGIT_MAX );
-
- printf( "\n****** %s ******\n", HugeCalc::GetTimerStr( FT_DOT06SEC_s ) );
- system( "pause" );
-
- return 0;
- }
复制代码 上述代码经过了一些优化,效率非常高。
若将宏 DIGIT_MAX 定义成 128,则 2.371397 s 内就可得到全部 1105 组解:- . . .
- 00:00:00.985 No.1084 exp( 2, 3, 7 ) = ( 7, 4, 20 )
- 00:00:00.986 No.1085 exp( 2, 3, 7 ) = ( 43, 10, 20 )
- 00:00:00.988 No.1086 exp( 2, 3, 7 ) = ( 51, 21, 20 )
- 00:00:01.014 No.1087 exp( 2, 3, 7 ) = ( 5, 11, 21 )
- 00:00:01.017 No.1088 exp( 2, 3, 7 ) = ( 16, 27, 21 )
- 00:00:01.040 No.1089 exp( 2, 3, 7 ) = ( 12, 2, 22 )
- 00:00:01.042 No.1090 exp( 2, 3, 7 ) = ( 36, 4, 22 )
- 00:00:01.042 No.1091 exp( 2, 3, 7 ) = ( 20, 5, 22 )
- 00:00:01.047 No.1092 exp( 2, 3, 7 ) = ( 9, 31, 22 )
- 00:00:01.068 No.1093 exp( 2, 3, 7 ) = ( 15, 0, 23 )
- 00:00:01.069 No.1094 exp( 2, 3, 7 ) = ( 4, 1, 23 )
- 00:00:01.069 No.1095 exp( 2, 3, 7 ) = ( 5, 1, 23 )
- 00:00:01.069 No.1096 exp( 2, 3, 7 ) = ( 8, 3, 23 )
- 00:00:01.070 No.1097 exp( 2, 3, 7 ) = ( 7, 8, 23 )
- 00:00:01.070 No.1098 exp( 2, 3, 7 ) = ( 21, 9, 23 )
- 00:00:01.123 No.1099 exp( 2, 3, 7 ) = ( 5, 2, 25 )
- 00:00:01.151 No.1100 exp( 2, 3, 7 ) = ( 5, 6, 26 )
- 00:00:01.185 No.1101 exp( 2, 3, 7 ) = ( 1, 23, 27 )
- 00:00:01.258 No.1102 exp( 2, 3, 7 ) = ( 26, 10, 30 )
- 00:00:01.448 No.1103 exp( 2, 3, 7 ) = ( 19, 0, 38 )
- 00:00:01.452 No.1104 exp( 2, 3, 7 ) = ( 4, 17, 38 )
- 00:00:01.557 No.1105 exp( 2, 3, 7 ) = ( 14, 4, 43 )
-
- ****** 2.371397 s ******
- 请按任意键继续. . .
复制代码 |
-
-
D128.txt
56.18 KB, 下载次数: 1, 下载积分: 金币 -1 枚, 经验 1 点, 下载 1 次
运行结果
|