Problem: Example

Input

20


Output

4

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int n;
int a[15];
unordered_map<ll,ll> dp[15][130][3];
ll asum,aprod=1;

int main(){
  {
    string in;
    cin>>in;
    n=in.size();
    rep(i,n){
      a[i]=in[i]-'0';
      asum+=a[i];
      aprod*=a[i]+1;
    }
  }
  dp[0][0][1][1]=1;
  rep(i,n){
    rep(j,130){
      rep(k,3){
        for(P p : dp[i][j][k]){
          rep(nxtd,10){
            if(k==0||k==2){
              dp[i+1][j+nxtd][k][p.fi*(nxtd+1)]+=p.se;
            }else{
              if(nxtd<a[i]){
                dp[i+1][j+nxtd][0][p.fi*(nxtd+1)]+=p.se;
              }else if(nxtd==a[i]){
                dp[i+1][j+nxtd][1][p.fi*(nxtd+1)]+=p.se;
              }else if(nxtd>a[i]){
                dp[i+1][j+nxtd][2][p.fi*(nxtd+1)]+=p.se;
              }
            }
          }
        }
      }
    }
  }
  ll res=0;
  rep(j,130)rep(k,3){
    for(P p : dp[n][j][k]){
      if(j<asum||(j==asum&&p.fi<aprod)||(j==asum&&p.fi==aprod&&k<2))res+=p.se;
    }
  }
  cout<<res-1<<endl;
  return 0;
}