#include <bits/stdc++.h>
int main() {
  int i, j, a[10], n, t, d, x;
  while (scanf("%d", &x) != EOF) {
    for (i = 0; i < 10; i++) a[i] = -1;
    t = x;
    do {
      a[t % 10] = 1;
    } while (t /= 10);
    for (i = 1, n = 0; i * i <= x; i++) {
      if (x % i == 0) {
        t = i;
        do {
          if (a[t % 10] == 1) {
            n++;
            break;
          }
        } while (t /= 10);
        t = x / i;
        if (t != i) do {
            if (a[t % 10] == 1) {
              n++;
              break;
            }
          } while (t /= 10);
      } else
        continue;
    }
    printf("%d\n", n);
  }
  return 0;
}
