#include <bits/stdc++.h>
using namespace std;
vector<int> dig;
void digit(int n) {
  while (n > 0) {
    dig.push_back(n % 10);
    n /= 10;
  }
}
vector<int> d;
int main() {
  int n;
  scanf("%d", &n);
  int sq = (int)sqrt(n + .0);
  for (int i = 1; i <= sq; i++) {
    if (n % i == 0) d.push_back(i);
  }
  int sz = d.size();
  for (int i = sz - 1; i >= 0; i--) {
    int k = (n / d[i]);
    d.push_back(k);
  }
  sort(d.begin(), d.end());
  d.erase(unique(d.begin(), d.end()), d.end());
  digit(n);
  int sz1 = d.size();
  int sz2 = dig.size();
  int ct = 0;
  for (int i = 0; i < sz1; i++) {
    while (d[i] > 0) {
      bool ck = 0;
      int rem = d[i] % 10;
      for (int i = 0; i < sz2; i++) {
        if (rem == dig[i]) {
          ct++;
          ck = 1;
          break;
        }
      }
      if (ck) break;
      d[i] /= 10;
    }
  }
  cout << ct << endl;
  return 0;
}
