#include<studio.h>
#inclued<math.h>
#include<windows.h>
#define MAX_NUM 30
#define _PRINT_0
unsigned long Result[MAX_NUM * MAX_NUM], ResultNum, Used[MAX_NUM * MAX_NUM]={0}
boolPrimeTable[MAX_NUM * MAX_NUM * 2]={ false }
unsigned long N, QN
void CreatePrimeTable(void)
{
PrimeTable[0]=false
PrimeTable[1]=false
PrimeTable[2]=true
PrimeTable[3]=true
for(unsigned long j=5j <= MAX_NUM * MAX_NUM * 2j+=2)
{
PrimeTable[j]=true
for(unsigned long i=3i <= sqrt((double)j)i+=2)
{
if(j % i == 0)
{
PrimeTable[j]=false
break
}
}
}
}
inline bool IsPrime(unsigned long n)
{
return PrimeTable[n]
}
bool CheckIt(unsigned long Deep)
{
if(Deep == 0)
{
return true
}
else if(Deep <N)
{
return IsPrime(Result[Deep] + Result[Deep - 1])
}
else if(Deep % N == 0)
{
return IsPrime(Result[Deep] + Result[Deep - N])
}
else
{
return(IsPrime(Result[Deep] + Result[Deep - 1]) &&IsPrime(Result[Deep] + Result[Deep - N]))
}
}
void go(unsigned long Deep)
{
if(Deep == QN)
{
ResultNum++
#if (_PRINT_)
printf("Find it! No.%lu\n", ResultNum)
for(unsigned long i=0i <QNi++)
{
printf("%lu\t", Result[i])
if(i % N == N - 1)
{
printf("\n")
}
}
#else
printf("\rFind:%lu", ResultNum)
#endif
}
else
{
for(unsigned long i=1i <= QN++i)
{
if(!Used[i])
{
Result[Deep]=i
if(CheckIt(Deep))
{
Used[i]=1
go(Deep + 1)
Used[i]=0
}
}
}
}
}
int main()
{
DWORD tim
ResultNum=0
printf("Input N:")
scanf("%lu", &N)
QN=N * N
tim=GetTickCount()
CreatePrimeTable()
go(0)
printf("\n\nN=%lu\n", N)
printf("Total=%lu\n", ResultNum)
printf("Time=%lu\n", GetTickCount() - tim)
return 0
}
《Go程序设计语言中文版》百度网盘pdf最新全集下载:
链接:https://pan.baidu.com/s/1K2XHYlNbRyQMiBkckaPr7A
?pwd=0cii 提取码:0cii简介:本书由《C程序设计语言》的作者Kernighan和谷歌公司Go团队主管Alan Donovan联袂撰写,是学习Go语言程序设计的指南。本书共13章,主要内容包括:Go的基础知识、基本结构、
基本数据类型、复合数据类型、函数、方法、接口、goroutine、通道、共享变量的并发性、包、go工具、测试、反射等。
本书适合作为计算机相关专业的教材,也可供Go语言爱好者阅读