#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 30;
int sum,m;
int num[N];
bool used[N];
int cnt;
int calc(int l,int r) //分成三段每一段的值a,b,c 分别算出
{
int res = 0;
for(int i = l;i <= r;i ++ )
{
res = res*10 + num[i];
}
return res;
}
void dfs(int u) //u表示自己带入数组的次数
{
int a,b,c;
if(u > 8) //大于 8 9次循环全部代入计算a,b,c计算
for(int i = 0;i < 7;i ++ )
for(int j = i + 1;j < 8;j ++ ){
a = calc(0,i);
b = calc(i+1,j);
c = calc(j+1,8);
if(c*sum - a*c == b){
cnt ++;
}
}
for(int i = 1;i <= 9;i ++ ) //全排列 1 ~ 9 方便“暴力”切割
{
if(!used[i])
{
num[u] = i;
used[i] = 1;
dfs(u + 1);
used[i] = 0;
}
}
}
int main()
{
cin >> sum;
dfs(0);
cout << cnt;
return 0;
}
//暴力算法
标签:calc,num,递归,int,res,带分数,used,打卡,include From: https://www.cnblogs.com/poemgranate/p/17382907.html