#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100;
int f[maxn];
int a[maxn];
char s[maxn];
int main() {
  int d;
  scanf("%d", &d);
  scanf("%s", s);
  int len = strlen(s);
  a[1] = s[0] - '0';
  for (int i = 1; i < len; i++) {
    a[i + 1] = a[i] + (s[i] - '0');
  }
  for (int i = 1; i <= len; i++) {
    for (int j = 0; j < i; j++) {
      f[a[i] - a[j]]++;
    }
  }
  long long ans = 0;
  for (int i = 1; i < maxn; i++) {
    if (d % i) continue;
    if ((d / i) >= maxn) continue;
    ans += (long long)f[i] * f[d / i];
  }
  if (d == 0) {
    for (int i = 0; i < maxn; i++) ans += (long long)f[0] * f[i];
  }
  printf("%I64d\n", ans);
}
