###### Codeforces Problem 161E - Polycarpus the Safecracker

具体解某个数时暴力即可

#include<stdio.h>
#include<math.h>
#include<vector>
#include<string.h>
using namespace std;
bool vis[100010];
vector<int>dp[5][100010];
int k,l;
int a[6][6];
int dfs(int now){
int i,j,x=0,sum=0;
for(i=0;i<now;i++)
x=x*10+a[now][i];
if(i==l-1)
return dp[1][x].size();
for(i=0;i<dp[l-now][x].size();i++){
int tem=dp[l-now][x][i];
for(j=l-1;j>=now;j--){
a[j][now]=a[now][j]=tem%10;
tem/=10;
}
sum+=dfs(now+1);
}
return sum;
}
int main(){
int i,j,n;
int m=sqrt(100000.5);
for(i=2;i<=m;i++)
if(!vis[i]){
for(j=i*i;j<=100000;j+=i)
vis[j]=1;
}
for(i=2;i<100000;i++)
if(!vis[i]){
int tem=i;
tem/=10;
for(j=1;j<=4;j++){    //表示5位数有j位个未确定
dp[j][tem].push_back(i);
tem/=10;
}
}
scanf("%d",&n);
char str[7];
for(j=1;j<=n;j++){
scanf("%s",str);
l=strlen(str);
for(i=0;str[i]!='\0';i++){
a[0][i]=a[i][0]=str[i]-'0';
}
printf("%d\n",dfs(1));
}
}

#### Codeforces 246B-Increase and Decrease【模拟】

2016-05-03 18:54:50

#### Codeforces #211 (Div. 2) B. Fence

2013-11-11 20:47:11

#### Codeforces-189A-Cut Ribbon

2016-09-19 22:22:31

#### codeforces——189A——Cut Ribbon

2017-06-01 19:38:56

#### Codeforces Round #241 (Div. 2) 解题报告

2014-04-17 14:07:13

#### CodeForces 219B (思维)

2017-02-14 19:40:14

#### codeforces 416D Population Size

2015-12-04 23:41:20

#### Codeforces 371C Hamburgers

2014-07-27 16:11:43

#### CodeForces 163A Substring and Subsequence（DP）

2016-04-13 16:04:30

#### Codeforces 246B Increase and Decrease 【数学】

2016-05-01 18:20:47

## 不良信息举报

Codeforces Problem 161E - Polycarpus the Safecracker