标签:des style blog http io ar color os sp
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 28064 Accepted Submission(s): 12487
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstdlib> 5 #include<cstring> 6 using namespace std; 7 int prime[40],vis[40]; 8 int a[40],n; 9 10 int dfs(int x) 11 { 12 if(x==n && !prime[a[n]+a[1]]) 13 { 14 for(int i=1;i<=n;i++) 15 { 16 if(i==1) 17 printf("%d",a[i]); 18 else 19 printf(" %d",a[i]); 20 } 21 printf("\n"); 22 } 23 else 24 { 25 for(int i=2;i<=n;i++) 26 { 27 if(!vis[i] && !prime[i+a[x]]) 28 { 29 vis[i]=1; 30 a[x+1]=i; 31 dfs(x+1); 32 vis[i]=0; 33 } 34 } 35 } 36 } 37 38 int main() 39 { 40 int k=0,j; 41 while(cin >> n) 42 { 43 memset(prime,0,sizeof(prime)); 44 memset(vis,0,sizeof(vis)); 45 k++; 46 47 prime[1]=1; 48 for(int i=2;i<=n*2;i++) 49 { 50 if(!prime[i]) 51 for(j=i+i;j<=n*2;j+=i) 52 { 53 prime[j]=1; 54 } 55 } 56 printf("Case %d:\n",k); 57 a[1]=1; 58 dfs(1); 59 printf("\n"); 60 } 61 return 0; 62 }
标签:des style blog http io ar color os sp
原文地址:http://www.cnblogs.com/xuesen1995/p/4109570.html