| 
注册时间2007-12-26最后登录1970-1-1威望 星金币 枚贡献 分经验 点鲜花 朵魅力 点上传 次下载 次积分92885在线时间 小时 
 | 
 
 发表于 2008-11-21 16:22:57
|
显示全部楼层 
对应代码| 运行 2.38 秒即可输出全部结果。复制代码//////////////////////////////////////////////////////////////////////////
//
// 目的:搜索串珠素数(形如abcabc...a(ab)的素数)
// 设计:郭先强 ( gxqcn@163.com; HugeCalc@Gmail.com )
// 日期:2008-11-21
//
// Web: http://www.emath.ac.cn/
// BBS: http://bbs.emath.ac.cn/
//
//////////////////////////////////////////////////////////////////////////
// Project -> Setting -> C/C++ -> Code Generation --> Use run-time library:
//      Win32 Debug:    Debug Multithreaded DLL
//      Win32 Release:  Multithreaded DLL
#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 MAX_DIGITS    100
int main(int argc, char* argv[])
{
    printf( "Call %s\n\n", HugeCalc::GetVer());
    if ( HC_LICENSE_NONE == HugeCalc::GetLicenseLevel() )
    {
        printf( "\n警告:您未通过 HugeCalc.dll 的许可认证!" \
            "\n解决方案可选下列方案之一:" \
            "\n    一、请将本程序移动到“/CopyrightByGuoXianqiang/[../]”目录下运行;" \
            "\n    二、或请在 HugeCalc.chm 中进行注册(一劳永逸)。" );
    }
    else
    {
        UINT32 n=0, a, b, c, s, count=0;
        CHugeInt stepA(1001), stepB, stepC, p;
        HugeCalc::EnableTimer();
        HugeCalc::ResetTimer();
        while(++n)
        {
            /* abcabc...abca 型  */
            if ( 3*n + 1 > MAX_DIGITS )
            {
                break;
            }
            ( stepC = stepA ).DecRShift( 2 );
            for ( a=1, p=stepA; a<10; a+=2, ++p+=stepA )
            {
                for ( b=0, s=(n+1)*a; b<10; ++b, s-=n*9 )
                {
                    for ( c=0; c<10; ++c, s+=n )
                    {
                        if ( 0!=(s%3) && p.IsPrime() )
                        {
                            printf( "%s\tNo.%u\t(digits,a,b,c)=(%u,%u,%u,%u)\t%s\n",
                                HugeCalc::GetTimerStr(), ++count, 3*n+1, a, b, c, (LPCTSTR)p );
                        }
                        p += stepC;
                    }
                }
            }
            /* abcabc...abcab 型  */
            if ( 3*n + 2 > MAX_DIGITS )
            {
                break;
            }
            stepB = stepA;
            stepC.DecLShift( 1 );
            stepA.DecLShift( 1 );
            for ( a=1, (p=stepA)+=stepB; a<10; ++a )
            {
                for ( b=1, s=(n+1)*(a+b); b<10; b+=2, s-=n*8-2, ++p+=stepB )
                {
                    for ( c=0; c<10; ++c, s+=n )
                    {
                        if ( 0!=(s%3) && p.IsPrime() )
                        {
                            printf( "%s\tNo.%u\t(digits,a,b,c)=(%u,%u,%u,%u)\t%s\n",
                                HugeCalc::GetTimerStr(), ++count, 3*n+2, a, b, c, (LPCTSTR)p );
                        }
                        p += stepC;
                    }
                }
            }
            ++stepA.DecLShift( 2 );
        }
    }
    system( "pause" );
    return 0;
}
 | 
 |