找一个含有你生日字串的回文素数
有帖子快速求出10^12以内回文素数,我突然想到,搜索一回文素数,使之含有自己身份证上的连续数字,说干就干。
写了一段代码:// 对应帖号: http://bbs.emath.ac.cn/viewthread.php?tid=284&page=1&fromuid=8#pid2303
// 请复制并覆盖 HugeCalc 安装包解压后的 ansi_c++.cpp 文件,
// 然后,修改你需要的字串,编译,运行。。。
#include <iostream.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" )
int main(int argc, char* argv[])
{
cout << "Call " << HugeCalc::GetVer() << endl;
if ( HC_LICENSE_NONE == HugeCalc::GetLicenseLevel())
{
cout << endl << "警告:您未通过 HugeCalc.dll 的许可认证!" \
<< endl << endl << "解决方案可选下列方案之一:" \
<< endl << " 一、请将本程序移动到“/CopyrightByGuoXianqiang/[../]”目录下运行;" \
<< endl << " 二、或请在 HugeCalc.chm 中进行注册(一劳永逸)。" \
<< endl << endl;
system( "pause" );
return (-1);
}
const CHAR chNum[] = "33:31 52-21-7002"; // 含有目标数字字串
const CHAR chRev[] = "2007-12-25 13:33"; // 反序字串
CHugeInt hugeHead(chNum);
CHugeInt hugeTail(chRev); // 请确保末位为 1、3、7、9 之一
CHugeInt hugeMean;
CHugeInt hugeTry;
const UINT32 mod3 = hugeTail % 3;
const UINT32 d = hugeTail.GetDigits();
// 初始化
HugeCalc::EnableTimer( TRUE );
HugeCalc::ResetTimer();
for ( UINT32 m = 0; m <= 9; ++m )
{
hugeHead = chNum;
// 避免:hugeTry 始终为合数情形
if ( 0 == m && hugeTry.Gcd( hugeHead, hugeTail ) != 1 )
{
++m;
}
// 防止:hugeTry 始终能被3整除情形
if ( ( mod3 * 2 + ( m % 3 )) % 3 == 0 \
&& ++m > 9 )
{
break;
}
( hugeMean = m );
hugeMean.DecLShift( d );
hugeHead.DecLShift( d + 1 );
while( !((( hugeTry = hugeHead ) += hugeMean ) += hugeTail ).IsPrime())
{
hugeMean *= 10;
hugeHead *= 100;
}
cout << endl << "m = " << m << "\t" << hugeTry.GetStr( FS_NORMAL ) \
<< "\t(" << hugeTry.GetDigits() << " digits)" << endl;
}
HugeCalc::EnableTimer( FALSE );
cout << endl << "耗时为:" << HugeCalc::GetTimerStr( FT_DOT06SEC_s ) << endl << endl;
system( "pause" );
return 0;
}运行结果如下:Call HugeCalc V8.0.0.0
m = 1 3331522170020000000000000000000000001000000000000000000000000200712251333 (73 digits)
m = 3 33315221700200000000000300000000000200712251333 (47 digits)
m = 4 3331522170024200712251333 (25 digits)
m = 6 333152217002000000000060000000000200712251333 (45 digits)
m = 7 3331522170020000007000000200712251333 (37 digits)
m = 9 333152217002090200712251333 (27 digits)
耗时为:0.007508 s
请按任意键继续. . .
备注:本论坛重建于 2007-12-25 13:33,所以特拿该字串为特征字串为例。 73位那个不一定是素数
不是素数的可能是0.01%
:lol
我看能找到证明工具和分解工具么?
应该是无法分解的
=============================
全都瞬间判定可能是素数 :) http://www.kongfz.com/bookstore/5097/book_18547154.html
无言了, 旧书这么贵啊 HugeCalc 的 IsPrime() 是可信的。
对程序常量字符串略作修改,得到如下结果:Call HugeCalc V8.0.0.0
m = 1 1234567890000001000000987654321 (31 digits)
m = 2 123456789000020000987654321 (27 digits)
m = 4 1234567894987654321 (19 digits)
m = 5 123456789000000000000000000050000000000000000000987654321 (57 digits)
m = 7 12345678900700987654321 (23 digits)
m = 8 12345678900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000987654321 (767 digits)
耗时为:7.114510 s
请按任意键继续. . . 我用的那个程序是基于雅克比和测试的
具体原理俺不清楚,因为没代码
用mathematica进行计算的代码!
Do[a = 333152217002*10^n + m*10^((n + 11)/2) + 200712251333;If, Print[{a, m, n + 12}]], {m, 1, 9}, {n, 1, 80,
2}]
其结果
{333152217002000000000000000000000000100000000000000000000000020071225\1333,1,73}
{33315221700200000000000300000000000200712251333,3,47}
{3331522170024200712251333,4,25}
{333152217002000000000060000000000200712251333,6,45}
{333152217002000000000000000000000060000000000000000000000200712251333\
,6,69}
{3331522170020000007000000200712251333,7,37}
{333152217002000000000000000000000000700000000000000000000000020071225\
1333,7,73}
{333152217002090200712251333,9,27}
结果说明:其格式为{回文素数,中间的那个数字,位数}
疑问!
郭先强先生的那个代码真长,以至于我都不想看一下,虽然有注释。不知道我的输出结果为什么比郭先强多出两个,疑惑中...........
再来一个!
{123456789000000000000000000000000000000000000000000000000000000000000\0000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000\
0000000000004000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000000000\
000000000000000987654321,4,1002}
忘记加代码了!
Do[a = 123456789*10^n + m*10^((n + 8)/2) + 987654321;If, Print[{a, m, n + 8}]], {m, 1, 9}, {n, 9, 1000}]
输出结果有些长,所以就不输出了!
页:
[1]
2