#include <bits/stdc++.h>
int main() {
  bool s[12], f;
  int n, d, i, sum = 0, k;
  scanf("%d", &n);
  for (i = 0; i <= 9; i++) s[i] = 0;
  k = n;
  while (k > 0) {
    s[k % 10] = 1;
    k /= 10;
  }
  for (d = 1; d <= sqrt(n) + 1; d++)
    if (n % d == 0) {
      int k = d;
      while (k > 0) {
        if (s[k % 10]) {
          sum++;
          break;
        }
        k /= 10;
      }
      if (n / d == d || d == 1) continue;
      k = n / d;
      while (k > 0) {
        if (s[k % 10]) {
          sum++;
          break;
        }
        k /= 10;
      }
    }
  if (d <= n) sum++;
  printf("%d\n", sum);
  return 0;
}
