求各位聚聚帮我看看哪错了吧/kel
代码:
#include<bits/stdc++.h>
using namespace std;
int n,a[105],qwq;
bool f[105],s;
void p()
{
for(int i=1;i<n;i++) printf("%d ",a[i]);
printf("%d",a[n]);
cout<<endl;
}
bool judge(int x)
{
int i;
i=2;
while(i<=sqrt(x)&&x%i!=0) i++;
if(i>sqrt(x)) return 1;
else return 0;
}
void dfs(int x)
{
int j;
if(x>n)
{
if(judge(a[n]+a[1]))
{
p();
s=true;
}
return;
}
for(j=1;j<=n;j++)
if(!f[j]&&judge(j+a[x-1]))
{
a[x]=j;
f[j]=true;
dfs(x+1);
f[j]=false;
}
}
int main()
{
while(cin>>n&&n!=EOF)
{
qwq++;
printf("Case %d:\n",qwq);
a[1]=1;
f[1]=true;
dfs(2);
if(!s) cout<<"No Solution"<<endl;
cout<<endl;
}
return 0;
}
马蜂有点奇怪,不要在意qwq