#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > p;
int a[10];
int ans;
void dfs(int d, int n, int m) {
  if (d >= n) {
    while (m) {
      if (a[m % 10] > 0) {
        ans++;
        break;
      }
      m /= 10;
    }
  } else {
    for (int i = 0; i <= p[d].second; i++) {
      dfs(d + 1, n, m);
      m *= p[d].first;
    }
  }
}
int main() {
  int x;
  while (cin >> x) {
    if (x == 1) {
      cout << 1 << endl;
      continue;
    }
    p.clear();
    int y = x;
    memset(a, 0, sizeof(a));
    while (y) {
      a[y % 10]++;
      y /= 10;
    }
    for (int i = 2; i * i <= x; i++) {
      if (x % i == 0) {
        int cnt = 0;
        while (x % i == 0) {
          cnt++;
          x /= i;
        }
        p.push_back(make_pair(i, cnt));
      }
    }
    if (x != 1) p.push_back(make_pair(x, 1));
    ans = 0;
    dfs(0, p.size(), 1);
    cout << ans << endl;
  }
}
