题目描述:
输入一个正整数 n,对于所有 abcdefghij 求出满足 abcde / fghij = n 的个数,要求 aj 为数字 09,且不能重复,abcde 和 fghij 这两个数可能有前缀 0。
62
2
#include <bits/stdc++.h>
using namespace std;
int n,s=0,an[15],v[15];
int ch(){
int a=0,b=0;
for(int i=1;i<=5;i++)a=a*10+an[i];
for(int i=6;i<=10;i++)b=b*10+an[i];
if(n*b==a)return 1;
else return 0;
}
void f(int x){
if(x==11){
if(ch())
s++;
return;
}
for(int i=0;i<=9;i++){
if(!v[i]){
an[x]=i;
v[i]=1;
f(x+1);
v[i]=0;
}
}
}
int main(){
cin>>n;
f(1);
cout<<s;
return 0;
}