#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
bool check(int a, int b) {
  long long c1 = 0, c2 = 0;
  while (a) {
    c1 |= 1 << a % 10;
    a /= 10;
  }
  while (b) {
    c2 |= 1 << b % 10;
    b /= 10;
  }
  return c2 & c1;
}
int main() {
  int x;
  scanf("%d", &x);
  set<int> div;
  for (int i = 1; i * i <= x; i++)
    if (!(x % i)) {
      div.insert(i);
      div.insert(x / i);
    }
  set<int>::iterator i;
  int ans = 0;
  for (i = div.begin(); i != div.end(); i++)
    if (check(*i, x)) ans++;
  printf("%d", ans);
  return 0;
}
