3 条题解
-
0
100分优化:#include<bits/stdc++.h> using namespace std; int ans[9][20]={{},{0,2,3,5,7},{0,23,29,31,37,53,59,71,73,79},{0,233,239,293,311,313,317,373,379,593,599,719,733,739,797},{0,2333,2339,2393,2399,2939,3119,3137,3733,3739,3793,3797,5939,7193,7331,7333,7393},{0,23333,23339,23399,23993,29399,31193,31379,37337,37339,37397,59393,59399,71933,73331,73939},{0,233993,239933,293999,373379,373393,593933,593993,719333,739391,739393,739397,739399},{0,2339933,2399333,2939999,3733799,5939333,7393913,7393931,7393933},{0,23399339,29399999,37337999,59393339,73939133}}; int book[9]={0,4,9,14,16,15,12,8,5}; int main() { int n; scanf("%d",&n); for(int i=1;i<=book[n];i++) printf("%d\n",ans[n][i]); return 0; }
-
0
100分: #include <bits/stdc++.h> using namespace std; int n,prime[100000005],cnt,maxx; bool check[100000005];
void dfs(int t,int sum) { if(t==n+1) { printf("%d\n",sum); return ; } for(int i=1;i<=9;i++) { if(!check[sum10+i]) dfs(t+1,sum10+i); } return ; }
int main() { scanf("%d",&n); check[1]=1; maxx=9; for(int i=1;i<n;i++) maxx*=10,maxx+=9; for(int i=2;i<=maxx;i++) { if(!check[i]) prime[++cnt]=i; for(int j=1;j<=cnt && iprime[j]<=maxx;j++) { check[iprime[j]]=1; if(i%prime[j]==0) break; } } dfs(1,0); return 0; }
-
0
40分: #include <bits/stdc++.h> using namespace std; int n, sum = 1;
bool o(int t) { for (int i = 2; i <= sqrt(t); i++) { if (t % i == 0) return 0; } return 1; }
bool yu(int t) { for (int i = 1; i <= n; i++) { if (o(t) == 0 || t == 1) return 0; t /= 10; } return 1; }
void cha(int book) { if (book >= sum * 10) return; if (yu(book)) printf("%d\n", book); cha(book + 1); return; }
int main() { scanf("%d", &n); for (int i = 1; i < n; i++) sum *= 10; cha(sum); return 0; }
- 1
信息
- ID
- 939
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 4
- 标签
- 递交数
- 31
- 已通过
- 17
- 上传者