#include <bits/stdc++.h>
using namespace std;
const int MAX = 10;
bool mark[MAX];
int main() {
  int x, n;
  while (scanf("%d", &x) != EOF) {
    memset(mark, false, sizeof mark);
    n = x;
    while (n) {
      mark[n % 10] = true;
      n = n / 10;
    }
    int sum = 0;
    for (int i = 1; i * i <= x; ++i) {
      if (x % i == 0) {
        n = i;
        while (n) {
          if (mark[n % 10]) {
            ++sum;
            break;
          } else
            n = n / 10;
        }
        n = x / i;
        if (n != i)
          while (n) {
            if (mark[n % 10]) {
              ++sum;
              break;
            } else
              n = n / 10;
          }
      }
    }
    printf("%d\n", sum);
  }
  return 0;
}
