- 注册时间
- 2007-12-27
- 最后登录
- 1970-1-1
- 威望
- 星
- 金币
- 枚
- 贡献
- 分
- 经验
- 点
- 鲜花
- 朵
- 魅力
- 点
- 上传
- 次
- 下载
- 次
- 积分
- 40149
- 在线时间
- 小时
|
发表于 2008-2-14 18:23:58
|
显示全部楼层
新的代码:- // HugeCalcDemo.cpp : Defines the entry point for the console application.
- //
-
- // Project -> Setting -> C/C++ -> Code Generation --> Use run-time library:
- // Win32 Debug: Debug Multithreaded DLL
- // Win32 Release: Multithreaded DLL
-
- #include <time.h>
- #include <iostream>
- using namespace std;
- #include "../../../../HugeCalc_API/CppAPI/Include/HugeCalc.h" // 公共接口
- #include "../../../../HugeCalc_API/CppAPI/Include/HugeInt.h" // 10进制系统
- #include "../../../../HugeCalc_API/CppAPI/Include/HugeIntX.h" // 16进制系统
-
- #pragma message( "automatic link to ../../../../HugeCalc_API/CppAPI/Lib/HugeCalc.lib" )
- #pragma comment( lib, "../../../../HugeCalc_API/CppAPI/Lib/HugeCalc.lib" )
-
- // http://www.swox.com/gmp/#TRY
- // 1 + gcd(87324,78263148,7896) * (10^1989879887 mod 471!)
-
- #if 1
- #define _Test_HI
- #define integer CHugeInt
- #else
- #define _Test_HX
- #define integer CHugeIntX
- #endif
-
- #define SQRTSMALLPRIMES 4000
- #define SMALLPRIMES (SQRTSMALLPRIMES*SQRTSMALLPRIMES)
- int spcount;
- int sptable[SMALLPRIMES];
-
- #define LIMIT_SIZE 10000000
- #define RANGE (LIMIT_SIZE<<5)
- int mask[LIMIT_SIZE];
- #define SET_MASK(x) (mask[(x)>>5]|=1<<((x)&31))
- #define IS_SET(x) (mask[(x)>>5]&(1<<((x)&31)))
-
- void initsp()
- {
- int i,j;
- memset(sptable,-1,sizeof(sptable));
- sptable[0]=sptable[1]=0;
- for(i=2;i<SQRTSMALLPRIMES;i++){
- if(sptable[i]){
- for(j=i*i;j<SMALLPRIMES;j+=i){
- sptable[j]=0;
- }
- }
- }
- for(i=0,spcount=0;i<SMALLPRIMES;i++){
- if(sptable[i]){
- sptable[spcount++]=i;
- }
- }
- }
-
-
- int main(int argc, char* argv[])
- {
- // printf("Hello World!\n");
-
- cout << "Call " << HugeCalc::GetVer() << endl << endl;
-
- if ( HC_LICENSE_NONE == HugeCalc::GetLicenseLevel())
- {
- cout << endl << "警告:您未通过 HugeCalc.dll 的许可认证!" \
- << endl << endl << "解决方案可选下列方案之一:" \
- << endl << " 一、请将本程序移动到“/CopyrightByGuoXianqiang/[../]”目录下运行;" \
- << endl << " 二、或请在 HugeCalc.chm 中进行注册(一劳永逸)。" \
- << endl << endl;
- system( "pause" );
- return (-1);
- }
- // 初始化
- HugeCalc::EnableTimer( TRUE );
- HugeCalc::ResetTimer();
- HugeCalc::SeedRandom(time(NULL));
-
- initsp();
-
- integer hugeStart, hugeTemp;
- #ifdef _Test_HI
- hugeStart.Random(100);
- #else
- hugeStart.Random(335);
- #endif
- int m=hugeStart%30;
- m=15-m;
- if(m<0)m+=15;
- hugeStart+=m;///After the normalization, hugeStart%30==15
-
- int filter_list[]={-4,-2,2,4};
- int i;
- for(i=3;i<spcount;i++){//skip prime 2,3,5
- int p=sptable[i];
- m=hugeStart%p;
- int v=HugeCalc::InvertMod(30,p);
- int k;
- for(k=0;k<sizeof(filter_list)/sizeof(filter_list[0]);k++){
- long long s=-m+filter_list[k];
- while(s<0)s+=p;
- s*=v;
- s%=p;//hugeStart+s*30==filter_list[k] (mod p)
- int h;
- for(h=(int)s;h<RANGE;h+=p){
- SET_MASK(h);///Filter hugeStart+h*30
- }
- }
-
- }
-
- CONST UINT32 u32Timer_Filter = HugeCalc::GetTimer( TIMER_UNIT_ms );
- cout << "Filter cost "<<u32Timer_Filter<<"ms"<<endl;
- HugeCalc::ResetTimer();
- hugeStart-=4;
-
- int tcount=0,gcount=0;
-
- for(i=0;i<RANGE;i++){
- if(!IS_SET(i)){///hugeStart+i*30 may be a candidate
- tcount++;
- #if 0
- if(((hugeTemp=hugeStart)).TestPrimality(5)!=COMPOSITE&&
- (hugeTemp+=2).TestPrimality(5)!=COMPOSITE&&
- (hugeTemp+=4).TestPrimality(5)!=COMPOSITE&&
- (hugeTemp+=2).TestPrimality(5)!=COMPOSITE){
- #endif
- if(((hugeTemp=hugeStart)).IsPrime()&&
- (hugeTemp+=2).IsPrime()&&
- (hugeTemp+=4).IsPrime()&&
- (hugeTemp+=2).IsPrime()){
- ///Output the candidate;
- CONST LPCTSTR lpShow = hugeStart.GetStr( FS_DEFAULT );
- gcount++;
- cout<<"Found n,n+2,n+6,n+8 where n is "<<lpShow <<endl;
- }
- #if 0
- }
- #endif
-
- }
- hugeStart+=30;
- }
-
-
- // 记录计算耗时
- CONST UINT32 u32Timer_Calc = HugeCalc::GetTimer( TIMER_UNIT_ms );
-
-
- // 输出
- cout << "Total took " << u32Timer_Calc << " ms" << endl;
- cout << "Total test "<<tcount<<" Numbers, get "<<gcount<<" numbers"<<endl;
-
- system( "pause" );
-
- return 0;
- }
复制代码 |
|