#include <bits/stdc++.h>
using namespace std;
int d2x[] = {1, -1, 0, 0, 1, -1, 1, -1};
int d2y[] = {0, 0, 1, -1, 1, -1, -1, 1};
int d3x[] = {1, -1, 0, 0, 0, 0};
int d3y[] = {0, 0, 1, -1, 0, 0};
int d3z[] = {0, 0, 0, 0, 1, -1};
struct edge {
  int from, to, w;
  edge(int from, int to, int w) : from(from), to(to), w(w) {}
  bool operator<(const edge& e) const { return w > e.w; }
};
const double EPS = (1e-9);
long long n;
string str;
bitset<12> bits;
int cnt = 0;
char temp[1000];
int main() {
  cin >> str;
  istringstream iss(str);
  iss >> n;
  for (int i = 0; i < ((int)((str).size())); ++i) {
    bits[str[i] - '0'] = 1;
  }
  for (int i = 1; i * i <= n; ++i) {
    if (i * i == n) {
      sprintf(temp, "%d", i);
      str = string(temp);
      for (int j = 0; j < ((int)((str).size())); ++j) {
        if (bits[str[j] - '0']) {
          ++cnt;
          break;
        }
      }
    } else if (n % i == 0) {
      sprintf(temp, "%d", i);
      str = string(temp);
      for (int j = 0; j < ((int)((str).size())); ++j) {
        if (bits[str[j] - '0']) {
          ++cnt;
          break;
        }
      }
      sprintf(temp, "%d", n / i);
      str = string(temp);
      for (int j = 0; j < ((int)((str).size())); ++j) {
        if (bits[str[j] - '0']) {
          ++cnt;
          break;
        }
      }
    }
  }
  cout << cnt;
  return 0;
}
