#include <bits/stdc++.h>
using namespace std;
const int nMax = 100010;
const int nPre = 10100;
int pre[nPre], Div[nPre], num[nPre], a[nPre];
bool vis[nMax + 10], yes[20];
int tot = 0, Dep, ans;
void init() {
  int i, j;
  memset(vis, 0, sizeof(vis));
  for (i = 2; i < nMax; i++)
    if (!vis[i]) {
      pre[tot++] = i;
      for (j = 2 * i; j < nMax; j += i) vis[j] = true;
    }
}
void dfs(int dep) {
  int i, j, k, temp;
  if (dep > Dep) {
    temp = 1;
    for (i = 1; i <= Dep; i++)
      for (j = 1; j <= a[i]; j++) temp *= Div[i];
    bool flag = false;
    while (temp) {
      if (yes[temp % 10]) {
        flag = true;
        break;
      }
      temp /= 10;
    }
    if (flag) ans++;
    return;
  }
  for (i = 0; i <= num[dep]; i++) {
    a[dep] = i;
    dfs(dep + 1);
  }
}
int main() {
  init();
  int i, j, k, temp, n;
  while (scanf("%d", &n) != EOF) {
    memset(yes, 0, sizeof(yes));
    memset(num, 0, sizeof(num));
    temp = n;
    ans = 0;
    while (temp) {
      yes[temp % 10] = true;
      temp /= 10;
    }
    temp = n;
    Dep = 0;
    for (i = 0; i < tot && temp >= pre[i]; i++)
      if (temp % pre[i] == 0) {
        Dep++;
        Div[Dep] = pre[i];
        while (temp % Div[Dep] == 0 && temp) {
          temp /= Div[Dep];
          num[Dep]++;
        }
      }
    if (temp != 1) {
      Div[++Dep] = temp;
      num[Dep] = 1;
    }
    dfs(1);
    printf("%d\n", ans);
  }
  return 0;
}
