1 solutions
-
0
dfs
#include <bits/stdc++.h> using namespace std; int n; vector<int>v; int prime[1000000],opt; bool s[100010000]; bool fff(int x){ if(x==1||x==0) return 0; for(int i=2;i*i<=x;i++){ if(x%i==0) return 0; } return 1; } void dfs(int sum,int now){ if(sum==n){ for(int i:v){ cout<<i; } printf("\n"); return ; } for(int i=1;i<=9;i++){ if(fff(now*10+i)){ v.push_back(i); dfs(sum+1,now*10+i); v.pop_back(); } } } int main(){ cin>>n; dfs(0,0); return 0; }
- 1
Information
- ID
- 1279
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 9
- Tags
- # Submissions
- 22
- Accepted
- 4
- Uploaded By