解题思路:要使得
n
=
a
∗
b
c
n=a*{ b \over c}
n = a ∗ c b 先搜索a,在当前a的情况下搜索c,
b
=
n
∗
c
−
a
∗
c
b=n*c-a*c
b = n ∗ c − a ∗ c ,然后检查一下是否合法,合法则答案++。
#include <bits/stdc++.h>
#define x first
#define y second
#define mem(h) memset(h,-1,sizeof h)
#define mcp(a,b) memcpy(a,b,sizeof b)
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
typedef pair< int , int > PII;
typedef pair< double , double > PDD;
namespace IO{
inline LL read ( ) {
LL o= 0 , f= 1 ; char c= getchar ( ) ;
while ( c< '0' || c> '9' ) { if ( c== '-' ) f= - 1 ; c= getchar ( ) ; }
while ( c>= '0' && c<= '9' ) { o= o* 10 + c- '0' ; c= getchar ( ) ; }
return o* f;
}
} using namespace IO;
const int N= 1e3 + 7 , M= 2e3 + 7 , INF= 0x3f3f3f3f , mod= 1e9 + 7 , P= 131 ;
bool st[ 11 ] , bk[ 11 ] ;
int n, ans;
int check ( int a, int c) {
LL b= n* ( LL) c- a* c;
if ( ! a|| ! b|| ! c) return false ;
mcp ( bk, st) ;
while ( b) {
int x= b% 10 ;
b/ = 10 ;
if ( ! x|| bk[ x] ) return false ;
bk[ x] = 1 ;
}
for ( int i= 1 ; i<= 9 ; i++ ) {
if ( ! bk[ i] ) return false ;
}
return true ;
}
void dfs_c ( int a, int c) {
if ( check ( a, c) ) ans++ ;
for ( int i= 1 ; i<= 9 ; i++ ) {
if ( ! st[ i] ) {
st[ i] = 1 ;
dfs_c ( a, c* 10 + i) ;
st[ i] = 0 ;
}
}
}
void dfs_a ( int a) {
if ( a>= n) return ;
if ( a) dfs_c ( a, 0 ) ;
for ( int i= 1 ; i<= 9 ; i++ ) {
if ( ! st[ i] ) {
st[ i] = 1 ;
dfs_a ( a* 10 + i) ;
st[ i] = 0 ;
}
}
}
int main ( ) {
cin>> n;
dfs_a ( 0 ) ;
cout<< ans<< endl;
return 0 ;
}