#include <bits/stdc++.h>
using namespace std;
void divideByZero(const char* error) {
  printf(error);
  fclose(stdout);
  int a = 234;
  a = a / (a - a);
}
long parseLong() {
  long temp;
  scanf("%ld", &temp);
  return temp;
}
set<long long> getDigits(long long x) {
  set<long long> s;
  do s.insert(x % 10);
  while (x /= 10);
  return s;
}
bool isGood(set<long long>& digits, long long val) {
  do
    if (digits.find(val % 10) != digits.end()) return true;
  while (val /= 10);
  return false;
}
set<long long> getDivisors(long long x) {
  map<long long, long long> p;
  for (long long i = 2; i * i <= x; i++)
    while (x % i == 0) {
      p[i]++;
      x /= i;
    }
  if (x > 1) p[x] = 1;
  set<long long> d;
  d.insert(1);
  for (map<long long, long long>::iterator it = p.begin(); it != p.end();
       it++) {
    set<long long> prev = d, curr;
    for (set<long long>::iterator divisor = d.begin(); divisor != d.end();
         divisor++)
      for (long long i = 0, mult = 1; i <= it->second; i++, mult *= it->first)
        curr.insert((*divisor) * mult);
    d = curr;
  }
  return d;
}
int main() {
  long long x;
  scanf("%I64d", &x);
  set<long long> digits = getDigits(x);
  set<long long> divisors = getDivisors(x);
  long long count = 0;
  for (set<long long>::iterator it = divisors.begin(); it != divisors.end();
       it++)
    isGood(digits, *it) ? count++ : 0;
  printf("%I64d", count);
  return 0;
}
