#include <bits/stdc++.h>
using namespace std;
int d[100500];
int cnt[4000 * 90];
int sum[4000 + 100];
long long solve(int a, string s) {
  memset(cnt, 0, sizeof(cnt));
  int sz = 0;
  for (int i = 1; i * 1LL * i <= a; i++) {
    if (a % i == 0) {
      d[sz++] = i;
      if (i != a / i) d[sz++] = a / i;
    }
  }
  sum[0] = s[0] - '0';
  for (int i = 1; i < s.length(); i++) sum[i] = s[i] - '0' + sum[i - 1];
  for (int i = 0; i < s.length(); i++)
    for (int j = i; j < s.length(); j++)
      cnt[sum[j] - (i == 0 ? 0 : sum[i - 1])]++;
  long long res = 0;
  if (a == 0) {
    for (int i = 0; i <= 4000 * 9; i++)
      if (cnt[i] && i) res += cnt[0] * 2LL * cnt[i];
    return res + cnt[0] * 1LL * cnt[0];
  }
  for (int i = 0; i < sz; i++) {
    if (d[i] && d[i] <= 4000 * 9 && a / d[i] <= 4000 * 9) {
      res += cnt[d[i]] * 1LL * cnt[a / d[i]];
    }
  }
  return res;
}
long long slow(int a, string s) {
  sum[0] = s[0] - '0';
  for (int i = 1; i < s.length(); i++) sum[i] = s[i] - '0' + sum[i - 1];
  for (int i = 0; i < s.length(); i++)
    for (int j = i; j < s.length(); j++)
      cnt[sum[j] - (i == 0 ? 0 : sum[i - 1])]++;
  long long res = 0;
  for (int i = 0; i < s.length(); i++)
    for (int j = i; j < s.length(); j++)
      for (int ii = 0; ii < s.length(); ii++)
        for (int jj = ii; jj < s.length(); jj++)
          if ((sum[j] - (i == 0 ? 0 : sum[i - 1])) * 1LL *
                  ((sum[jj] - (ii == 0 ? 0 : sum[ii - 1]))) ==
              a)
            res++;
  return res;
}
void test() {
  srand(time(0));
  int a = rand() % 100;
  a = 0;
  string s = "";
  for (int i = 0; i < 10; i++) s += char(rand() % 10 + '0');
  cout << a << " " << s << endl;
  cout << solve(a, s) << " " << slow(a, s) << endl;
  assert(solve(a, s) == slow(a, s));
}
int main() {
  int a;
  string s;
  cin >> a >> s;
  cout << solve(a, s);
  return 0;
}
