标签:
# include <iostream> # include <cstring> # include <fstream> using namespace std; int n; int is[30], a[30]; bool Is(int x) { for(int i = 2; i * i <= x; i++) if(x % i == 0) return false; return true; } void dfs(int , int ); int main() { int k = 0; // fstream cin("aaa.txt"); while(cin >> n) { memset(is, 0, sizeof(is)); k++; cout << "Case " << k << ":" << endl; is[1] = 1; a[1] = 1; dfs(1, 2); cout << endl; } return 0; } void dfs(int x, int y) { for(int i = 2; i <= n; i++) { if(!is[i] && Is(x + i)) { is[i] = 1; a[y] = i; dfs(i, y + 1); is[i] = 0; } } if((y == n + 1) && Is(x + 1)) { for(int i = 1; i < n; i++) cout << a[i] << " "; cout << a[n] << endl; } }
标签:
原文地址:http://www.cnblogs.com/lyf-acm/p/5401991.html