mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
55 lines
1.2 KiB
C++
55 lines
1.2 KiB
C++
|
#include <iostream>
|
||
|
#include <cstdio>
|
||
|
#include <cstdlib>
|
||
|
using namespace std;
|
||
|
int ans[25];
|
||
|
int f[25];
|
||
|
int n;
|
||
|
int isprime(int x)
|
||
|
{
|
||
|
for(int i=2;i<=x/2;i++)
|
||
|
{
|
||
|
if(x%i==0)
|
||
|
return 0;
|
||
|
}
|
||
|
return 1;
|
||
|
}
|
||
|
void dfs(int k,int now)
|
||
|
{
|
||
|
if(k==n)
|
||
|
{
|
||
|
if(isprime(now+1))
|
||
|
{
|
||
|
ans[k]=now;
|
||
|
for(int i=0;i<n;i++)
|
||
|
{
|
||
|
printf("%d%c",ans[i],i==n-1?'\n':' ');
|
||
|
}
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
for(int i=2;i<=n;i++)
|
||
|
{
|
||
|
if(!f[i]&&isprime(now+i))
|
||
|
{
|
||
|
f[i]=1;
|
||
|
ans[k]=i;
|
||
|
dfs(k+1,i);
|
||
|
f[i]=0;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
int main()
|
||
|
{
|
||
|
int ncas=1;
|
||
|
while(scanf("%d",&n)!=EOF)
|
||
|
{
|
||
|
printf("Case %d:\n",ncas++);
|
||
|
memset(f,0,sizeof(f));
|
||
|
ans[0]=1;
|
||
|
dfs(1,1);
|
||
|
putchar('\n');
|
||
|
}
|
||
|
return 0;
|
||
|
}
|