#include <bits/stdc++.h>
using namespace std;
char s[4010];
int a[4010];
map<int, int> h;
int main() {
  int i, j, n, m;
  long long as = 0;
  scanf("%d%s", &m, s + 1);
  n = strlen(s + 1);
  for (i = 1; i <= n; i++) a[i] = s[i] - '0' + a[i - 1];
  for (i = 1; i <= n; i++)
    for (j = 1; j <= i; j++) h[a[i] - a[j - 1]]++;
  if (m == 0) {
    as = 2LL * h[0] * (n + n * (n - 1) / 2) - 1LL * h[0] * h[0];
    printf("%I64d\n", as);
    return 0;
  }
  for (i = 1; i < m / i; i++)
    if (m % i == 0) {
      as += 2LL * h[i] * h[m / i];
    }
  if (i * i == m) as += 1LL * h[i] * h[i];
  printf("%I64d\n", as);
  return 0;
}
