#include <bits/stdc++.h>
using namespace std;
const int oo = 2147483647;
int n, ans = 0, q[10];
int calc(int t1, int t2) {
  memset(q, 0, sizeof(q));
  while (t1) {
    q[t1 % 10] = 1;
    t1 /= 10;
  }
  while (t2) {
    if (q[t2 % 10]) return 1;
    t2 /= 10;
  }
  return 0;
}
int main() {
  cin >> n;
  int i;
  for (i = 1; i * i <= n; i++)
    if (n % i == 0) {
      ans += calc(i, n);
      if (n / i != i) ans += calc(n / i, n);
    }
  cout << ans << endl;
}
