- 注册时间
- 2007-12-26
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 92615
- 在线时间
- 小时
|
发表于 2009-8-25 16:56:05
|
显示全部楼层
下面的代码,用了 STL,还调用了 HugeCalc 以快速生成素数表及统计耗时:- #include <iostream>
- #include <algorithm>
- using namespace std;
-
- #include "../../../HugeCalc_API/CppAPI/Include/HugeCalc.h" // 公共接口
-
- #pragma message( "automatic link to ../../../HugeCalc_API/CppAPI/Lib/HugeCalc.lib" )
- #pragma comment( lib, "../../../HugeCalc_API/CppAPI/Lib/HugeCalc.lib" )
-
-
- int main(int argc, char* argv[])
- {
- // printf("Hello World!\n");
-
- cout << "Call " << HugeCalc::GetVer() << endl << endl;
-
- // 初始化
- HugeCalc::EnableTimer( TRUE );
- HugeCalc::ResetTimer();
-
- UINT32 i, j;
- UINT32 u32Size = HugeCalc::GetPrimeCount( 10000, 1899999 );
- UINT32 * pPrimeBuffer = new UINT32[u32Size];
- HugeCalc::GetPrimeList( pPrimeBuffer, u32Size, 10000, 1899999 );
-
- UINT32 LUT[720], u32Dights[6] = { 0, 1, 2, 5, 6, 7 };
- UINT32 *p, *p1, *p2, *p_end;
-
- *( p = LUT ) = 1256743; /* 012567 43 */
- while( next_permutation( u32Dights, u32Dights+6 ))
- {
- for ( i=0, j=0; 6!=j; ++j )
- {
- i = i * 10 + u32Dights[j];
- }
- *(++p) = i * 100 + 43;
- }
-
- p1 = pPrimeBuffer;
- do
- {
- p2 = lower_bound( p1, pPrimeBuffer + u32Size, (UINT32)((UINT64)18901256743 / *p1 ));
- p_end = lower_bound( p2, pPrimeBuffer + u32Size, (UINT32)((UINT64)18976521043 / *p1 )+1 );
-
- do
- {
- i = (UINT32)( UInt32x32To64( *p1, *p2 ) - (UINT64)18900000000 );
- p = lower_bound( LUT, LUT+720, i );
-
- if ( LUT+720 != p && i == *p )
- {
- cout << ((*p>=10000000)?"189":"1890") << *p << " = " << *p1 << " * " << *p2 << endl;
- }
- }while( p_end != ++p2 );
-
- } while( *(++p1) <= 99999 );
-
- delete []pPrimeBuffer;
-
- HugeCalc::EnableTimer( FALSE );
-
- cout << endl << "耗时为:" << HugeCalc::GetTimerStr( FT_DOT06SEC_s ) << endl;
-
- return 0;
- }
复制代码 请将上述代码复制粘贴进 [..]\CopyrightByGuoXianqiang\HugeCalc\testDLL\src\ANSI_C++\ansi_c++.cpp,然后编译运行即可。
它运行速度非常快,结果如下:- Call HugeCalc V8.1.0.0 (Win32)
-
- 18962715043 = 11173 * 1697191
- 18960217543 = 13037 * 1454339
- 18927156043 = 13187 * 1435289
- 18952607143 = 13291 * 1425973
- 18967512043 = 13799 * 1374557
- 18926501743 = 13841 * 1367423
- 18957201643 = 15077 * 1257359
- 18962107543 = 16223 * 1168841
- 18965210743 = 16631 * 1140353
- 18950726143 = 17123 * 1106741
- 18907561243 = 20357 * 928799
- 18965710243 = 21023 * 902141
- 18917062543 = 21817 * 867079
- 18927615043 = 21893 * 864551
- 18967102543 = 22247 * 852569
- 18920516743 = 25183 * 751321
- 18901652743 = 26501 * 713243
- 18910725643 = 28657 * 659899
- 18927610543 = 28807 * 657049
- 18912076543 = 29269 * 646147
- 18910765243 = 29569 * 639547
- 18912576043 = 33773 * 559991
- 18927160543 = 34351 * 550993
- 18961270543 = 34367 * 551729
- 18976105243 = 36527 * 519509
- 18965172043 = 37309 * 508327
- 18925160743 = 41981 * 450803
- 18910625743 = 42131 * 448853
- 18927016543 = 46171 * 409933
- 18921567043 = 46867 * 403729
- 18927561043 = 49463 * 382661
- 18951207643 = 52201 * 363043
- 18902756143 = 56893 * 332251
- 18970162543 = 66509 * 285227
- 18921675043 = 66571 * 284233
- 18917065243 = 70957 * 266599
- 18950126743 = 76603 * 247381
- 18925671043 = 83101 * 227743
- 18907652143 = 87049 * 217207
- 18916705243 = 95891 * 197273
- 18957062143 = 99023 * 191441
-
- 耗时为:0.174513 s
- Press any key to continue
复制代码 |
|