#include <bits/stdc++.h>
using namespace std;
int f[1550];
int init(int n) {
  int num = 0;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0 && n / i == i) {
      f[++num] = i;
      break;
    }
    if (n % i == 0) f[++num] = i, f[++num] = n / i;
  }
  return num;
}
int fan(int x, int y) {
  int p[30], q[30];
  for (int i = 0; i < 11; i++) p[i] = q[i] = 0;
  while (x) {
    p[x % 10] = 1;
    x /= 10;
  }
  while (y) {
    q[y % 10] = 1;
    y /= 10;
  }
  for (int i = 0; i <= 9; i++)
    if (p[i] && q[i]) return 1;
  return 0;
}
int main() {
  int n;
  while (cin >> n) {
    int num = init(n);
    int sum = 0;
    for (int i = 1; i <= num; i++) {
      sum += fan(f[i], n);
    }
    cout << sum << endl;
  }
}
