1 条题解
-
0
素数环
素数环一定是奇数偶数交替出现,所以一定不能是奇数个。
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6 + 10, INF = 0x3f3f3f3f, MOD = 1E9 + 7; int n, a[N], cnt; bool st[N]; bool isp(int n) { for (int i = 2; i <= n / i; i++) if (n % i == 0) return 0; return n > 1; } void dfs(int u) { if (cnt >= 10) exit(0); if (u > n) { if (isp(a[n] + a[1])) { for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl; cnt++; } return; } for (int i = 2; i <= n; i++) { if (!st[i] && isp(a[u - 1] + i)) { a[u] = i, st[i] = 1, dfs(u + 1); st[i] = 0; } } } int main(int argc, char* argv[]) { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; if (n & 1) exit(0); a[1] = st[1] = 1, dfs(2); return 0; }
- 1
信息
- ID
- 523
- 时间
- 2000ms
- 内存
- 128MiB
- 难度
- 7
- 标签
- 递交数
- 432
- 已通过
- 103
- 上传者