/*
答案:296962999629
耗时:0.0170646秒
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
using namespace std;
char cp[10000];//素数表
int main(void)
{
//建立素数表
memset(cp, 1, 9998 * sizeof(char));
for (int i = 2; i <= 100; ++i)
{
if (cp[i] == 0)
continue;
for (int j = i * i; j < 10000; j += i)
cp[j] = 0;
}
char str[12] = "";
for (int i = 1000; i < 10000; ++i)//枚举第一个素数
{
if (cp[i] == 0 || i == 1487)
continue;
char str1[8] = "";
_itoa(i, str1, 10);
sort(str1, str1 + 4);
bool bFind = false;
for (int j = i + 1; j < 10000; ++j)//枚举第二个素数
{
if (cp[j] == 0)
continue;
char str2[8] = "";
_itoa(j, str2, 10);
sort(str2, str2 + 4);
if (strcmp(str1, str2) != 0)//比对各位数字是否是排列
continue;
int nD = j - i;//计算公差
if (j + nD >= 10000)
continue;
if (cp[j + nD] == 1)//找到第三个候选数
{
char str3[8] = "";
_itoa(j + nD, str3, 10);
sort(str3, str3 + 4);
if (strcmp(str1, str3) != 0)//比对各位数字是否是排列
continue;
//找到了
bFind = true;
//拼接数字
_itoa(i, str1, 10);
strcat(str, str1);
_itoa(j, str2, 10);
strcat(str, str2);
_itoa(j + nD, str3, 10);
strcat(str, str3);
break;
}
}
if (bFind)
break;
}
cout << str << endl;
return 0;
}
|