#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int N = 30;
int n;
int a, b, c;
int cnt;
int l, r;
int stade[N];
bool used[N]; //true用过,false未用过
int calc(int l, int r)
{
int res = 0;
for (int i = r; i < r + l; i++) {
res = res * 10 + stade[i];
}
return res;
}
void dfs(int x)
{
if (x == 10) {
for (int i = 1; i <= 7; i++) {
for (int j = 1; j <= 8 - i; j++) {
a = calc(i, 1);
b = calc(j, i + 1);
c = calc(9 - i - j, i + j + 1);
if (a * c + b == n * c) {
cnt++;
}
}
}
return;
}
for (int i = 1; i <= 9; i++) {
if (!used[i]) {
stade[x] = i;
used[i] = true;
dfs(x + 1);
used[i] = false;
}
}
}
int main()
{
scanf("%d", &n);
dfs(1);
printf("%d\n", cnt);
return 0;
}
蓝桥杯——带分数
于 2024-04-04 18:14:19 首次发布