#include <bits/stdc++.h>
const int N = 4096;
int a, n, v[N], h;
long long w, c[N * 10];
char s[N];
int main() {
  std::cin >> a >> s;
  for (; s[n]; ++n) v[n + 1] = v[n] + s[n] - '0';
  h = v[n];
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j < i; ++j) ++c[v[i] - v[j]];
  if (a) {
    for (int i = 1; i <= h && i * i <= a; ++i)
      if (0 == a % i)
        if (a / i <= h) w += c[i] * c[a / i] * (i * i == a ? 1 : 2);
  } else
    w = c[0] * ((n + 1) * n - c[0]);
  std::cout << w << std::endl;
}
