标签:for c++ 矩阵 sizeof ace mat tab 不用 void
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int maxn = 1e5 + 5;
int T, p, len, ans;
int vis[maxn], table[6][6];
vector<int> re[6][maxn];
void Fill(int st, int k) {
for (int i = 5; i >= st; i--, k /= 10) {
table[st][i] = table[i][st] = k % 10;
}
}
void Pre() {
for (int i = 2; i < maxn - 5; i++) {
if (!vis[i]) {
for (int j = i * 2; j < maxn - 5; j += i)
vis[j] = 1;
for (int k = i, t = 1, j = 4; j; j--) {
t *= 10; k /= 10;
re[j][k].push_back(i % t);
}
}
}
}
void dfs(int depth, int tmp = 0) {
if (depth > 5) {
ans++;
return;
}
for (int i = 1; i < depth; i++)
tmp = tmp * 10 + table[depth][i];
for (int i : re[depth - 1][tmp]) {
Fill(depth, i);
dfs(depth + 1);
}
}
int main() {
Pre();
for (scanf("%d", &T); T; T--) {
scanf("%d", &p);
memset(table, 0, sizeof table);
ans = len = 0;
for (int k = p; k; k /= 10, len++);
Fill(5 - len + 1, p);
dfs(5 - len + 2);
printf("%d\n", ans);
}
return 0;
}
标签:for c++ 矩阵 sizeof ace mat tab 不用 void
原文地址:https://www.cnblogs.com/AlphaWA/p/10851967.html