标签:
Description
Input
Output
Sample Input
Sample Output
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,v[25],a[25]; int ssb[100],zj[100],pn; void f() { int i,j; zj[0]=1; zj[1]=1; pn=0; for (i=2;i<=100;i++) { if (zj[i]==0) ssb[pn++]=i; for (j=0;j<pn;j++) { if (i*ssb[j]>100) break; zj[i*ssb[j]]=1; if (i%ssb[j]==0) break; } } } void dfs(int x,int k) { int i,j; for (i=2;i<=n;i++) { if (!v[i]&&zj[i+x]==0) { v[i]=1; a[k+1]=i; if (k+1==n) { if (zj[1+a[n]]==0){ for (j=1;j<n;j++) printf("%d ",a[j]); printf("%d\n",a[n]);} } dfs(i,k+1); v[i]=0; } } } int main() { int cut=1; a[1]=1; memset(zj,0,sizeof(zj)); f(); while (~scanf("%d",&n)) { printf("Case %d:\n",cut); cut++; memset(v,0,sizeof(v)); dfs(1,1); printf("\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/pblr/p/4696365.html