#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX / 4;
const double EPS = 1e-12;
vector<int> getDivisor(int x) {
  set<int> res;
  for (int i = (int)(1); i < (int)(sqrt(x) + 1); ++i) {
    if (!(x % i)) {
      res.insert(i);
      res.insert(x / i);
    }
  }
  return vector<int>((res).begin(), (res).end());
}
string itostr(int x) {
  ostringstream oss;
  oss << x;
  return oss.str();
}
bool match(int x, int y) {
  string a, b;
  a = itostr(x);
  b = itostr(y);
  set<int> count((a).begin(), (a).end());
  for (int i = (int)(0); i < (int)(b.size()); ++i) {
    if (((count).find(b[i]) != (count).end())) {
      return true;
    }
  }
  return false;
}
int main() {
  int x;
  cin >> x;
  vector<int> divisor = getDivisor(x);
  int res = 0;
  for (int i = (int)(0); i < (int)(divisor.size()); ++i) {
    res += match(x, divisor[i]);
  }
  cout << res << endl;
  return 0;
}
