4
2333
2339
2393
2399
2939
3119
3137
3733
3739
3793
3797
5939
7193
7331
7333
7393
AC
1 #include <cmath> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 int n; 7 bool pd(int x)//判斷質數 8 { 9 if (x==1) 10 return false; 11 for (int i=2;pow(i,2)<=x;i++) 12 if (x%i==0) 13 return false; 14 return true; 15 } 16 void dfs(int dep,int fa)//找質數狀況下的特殊骨頭 17 { 18 for (int i=1;i<=9;i++) 19 if (pd(fa*10+i)) 20 { 21 if (dep==n) 22 printf("%d\n",fa*10+i); 23 else 24 dfs(dep+1,fa*10+i); 25 } 26 } 27 int main() 28 { 29 scanf("%d",&n); 30 dfs(1,0); 31 return 0; 32 }