#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long a, long long b) {
  return b == 0 ? a : gcd(b, a % b);
}
const int TAM = 1e5;
bool m[TAM + 1];
vector<long long> primes;
int main() {
  long long n, con = 0;
  cin >> n;
  vector<bool> d(10, 0);
  long long aux = n;
  while (aux >= 1) {
    d[aux % 10] = 1;
    aux /= 10;
  }
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      aux = i;
      while (aux >= 1) {
        if (d[aux % 10]) {
          con++;
          break;
        }
        aux /= 10;
      }
      if (n / i != i) {
        aux = n / i;
        while (aux >= 1) {
          if (d[aux % 10]) {
            con++;
            break;
          }
          aux /= 10;
        }
      }
    }
  }
  cout << con << '\n';
}
