#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 5;
int n;
bool a[10];
inline bool judge(int copy, int i) {
  memset(a, 0, sizeof(a));
  while (copy) {
    a[copy % 10] = true;
    copy /= 10;
  }
  while (i) {
    if (a[i % 10]) return true;
    i /= 10;
  }
  return false;
}
int main() {
  while (scanf("%d", &n) == 1) {
    if (n == 1)
      printf("1\n");
    else if (n == 2)
      printf("1\n");
    else {
      int ans = 0;
      for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
          if (judge(n, i)) ans++;
          if (i != n / i && judge(n, n / i)) ans++;
        }
      }
      printf("%d\n", ans);
    }
  }
}
